Skip to content

Commit e2fc113

Browse files
committed
Respect agent stop requests when retrying job acquisition
1 parent d746862 commit e2fc113

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

agent/agent_worker.go

+11
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,17 @@ func (a *AgentWorker) Ping(ctx context.Context) (*api.Job, error) {
550550
// state. If the job is in an unassignable state, it will return an error immediately.
551551
// Otherwise, it will retry every 3s for 30 s. The whole operation will timeout after 5 min.
552552
func (a *AgentWorker) AcquireAndRunJob(ctx context.Context, jobId string) error {
553+
ctx, cancel := context.WithCancel(ctx)
554+
go func() {
555+
for {
556+
time.Sleep(500 * time.Millisecond)
557+
if a.stopping {
558+
cancel()
559+
return
560+
}
561+
}
562+
}()
563+
553564
job, err := a.client.AcquireJob(ctx, jobId)
554565
if err != nil {
555566
return fmt.Errorf("failed to acquire job: %w", err)

0 commit comments

Comments
 (0)