Skip to content

Commit

Permalink
enhance(operate): check in loop more responsive to termination signal (
Browse files Browse the repository at this point in the history
…#596)

Co-authored-by: David May <[email protected]>
  • Loading branch information
ecrupper and wass3rw3rk authored Sep 20, 2024
1 parent 1b7be1a commit db0fc08
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/vela-worker/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ func (w *Worker) operate(ctx context.Context) error {

// spawn goroutine for phoning home
executors.Go(func() error {
// five second ticker for signal handling
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()

// initialize timer for check-in
timer := time.After(0)

for {
select {
case <-gctx.Done():
logrus.Info("completed looping on worker registration")
return nil
default:
case <-timer:
// check in attempt loop
for {
// register or update the worker
Expand Down Expand Up @@ -145,9 +152,12 @@ func (w *Worker) operate(ctx context.Context) error {
return err
}

// sleep for the configured time
time.Sleep(w.Config.CheckIn)
// set timer to next check in
timer = time.After(w.Config.CheckIn)
}

// five second ticker
<-ticker.C
}
})

Expand Down

0 comments on commit db0fc08

Please sign in to comment.