From db0fc08968b14b2a489d0aa54c24ea632d768541 Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:55:19 -0400 Subject: [PATCH] enhance(operate): check in loop more responsive to termination signal (#596) Co-authored-by: David May <49894298+wass3rw3rk@users.noreply.github.com> --- cmd/vela-worker/operate.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/vela-worker/operate.go b/cmd/vela-worker/operate.go index 0b96b5ea..ca8684e0 100644 --- a/cmd/vela-worker/operate.go +++ b/cmd/vela-worker/operate.go @@ -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 @@ -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 } })