Skip to content

Commit

Permalink
Respect agent stop requests when retrying job acquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
moskyb committed Jan 9, 2025
1 parent b6015a8 commit e2231e8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions agent/agent_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,17 @@ func (a *AgentWorker) Ping(ctx context.Context) (*api.Job, error) {
// state. If the job is in an unassignable state, it will return an error immediately.
// Otherwise, it will retry every 3s for 30 s. The whole operation will timeout after 5 min.
func (a *AgentWorker) AcquireAndRunJob(ctx context.Context, jobId string) error {
ctx, cancel := context.WithCancel(ctx)
go func() {
for {
time.Sleep(500 * time.Millisecond)
if a.stopping {
cancel()
return
}
}
}()

job, err := a.client.AcquireJob(ctx, jobId)
if err != nil {
return fmt.Errorf("failed to acquire job: %w", err)
Expand Down

0 comments on commit e2231e8

Please sign in to comment.