Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion cmd/bb_scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,29 @@ func main() {
actionRouter,
executeAuthorizer,
modifyDrainsAuthorizer,
killOperationsAuthorizer)
killOperationsAuthorizer,
)

// Force periodic cleanups of stale workers. This also
// happens automatically when RPCs occur, but that's not
// sufficient to ensure Prometheus metrics are updated
// if the final workers disappear.
//
// TODO: Maybe it's better to let InMemoryBuildQueue
// implement prometheus.Collector? Then cleanups can run
// whenever the scheduler is scraped.
dependenciesGroup.Go(func(ctx context.Context, siblingsGroup, dependenciesGroup program.Group) error {
t := time.NewTicker(time.Minute)
for {
select {
case <-t.C:
buildQueue.ForceCleanup()
case <-ctx.Done():
t.Stop()
return nil
}
}
})

// Create predeclared platform queues.
for _, platformQueue := range configuration.PredeclaredPlatformQueues {
Expand Down
9 changes: 9 additions & 0 deletions pkg/scheduler/in_memory_build_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,15 @@ func (bq *InMemoryBuildQueue) leave() {
bq.lock.Unlock()
}

// ForceCleanup forcefully runs any pending cleanup tasks. This method
// can be invoked periodically to ensure that workers are removed, even
// if no other RPC traffic occurs. This ensures that Prometheus metrics
// report the correct values.
func (bq *InMemoryBuildQueue) ForceCleanup() {
bq.enter(bq.clock.Now())
bq.leave()
}

// getIdleSynchronizeResponse returns a synchronization response that
// explicitly instructs a worker to return to the idle state.
func (bq *InMemoryBuildQueue) getIdleSynchronizeResponse() *remoteworker.SynchronizeResponse {
Expand Down