Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(operate): check in loop more responsive to termination signal #596

Merged
merged 2 commits into from
Sep 20, 2024
Merged
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
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
Loading