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

Continue heartbeat after stop signal #991

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions agent/agent_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func (a *AgentWorker) Start() error {
for {
select {
case <-time.After(heartbeatInterval):
if !a.running {
a.logger.Debug("Stopping heartbeats")
return
}

err := a.Heartbeat()
if err != nil {
// Get the last heartbeat time to the nearest microsecond
Expand All @@ -149,10 +154,6 @@ func (a *AgentWorker) Start() error {
a.logger.Error("Failed to heartbeat %s. Will try again in %s. (Last successful was %v ago)",
err, heartbeatInterval, time.Now().Sub(lastHeartbeat))
}

case <-a.stop:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other way to do this would be with a context with cancel:

ctx, cancel := context.WithCancel(context.Background()
defer cancel()
...
case <-ctx.Done():

a.logger.Debug("Stopping heartbeats")
return
}
}
}()
Expand Down