Skip to content

Commit

Permalink
fix(task): fix an issue where tasks fail to resume on claim (#14356)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyondhill authored Jul 16, 2019
1 parent c6f66e1 commit 10bfc91
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions task/backend/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ func (s *TickScheduler) ClaimTask(authCtx context.Context, task *platform.Task)
return err
}

s.taskSchedulers[task.ID] = ts

// pickup any runs that are still "running from a previous failure"
runs, err := s.taskControlService.CurrentlyRunning(authCtx, task.ID)
if err != nil {
Expand All @@ -320,6 +318,8 @@ func (s *TickScheduler) ClaimTask(authCtx context.Context, task *platform.Task)
}
}

s.taskSchedulers[task.ID] = ts

next, hasQueue := ts.NextDue()
if now := atomic.LoadInt64(&s.now); now >= next || hasQueue {
ts.Work()
Expand Down Expand Up @@ -509,8 +509,9 @@ func (ts *taskScheduler) Work() {
}

func (ts *taskScheduler) WorkCurrentlyRunning(runs []*platform.Run) error {
foundWorker := false

for _, cr := range runs {
foundWorker := false
for _, r := range ts.runners {
t, err := time.Parse(time.RFC3339, cr.ScheduledFor)
if err != nil {
Expand All @@ -523,9 +524,10 @@ func (ts *taskScheduler) WorkCurrentlyRunning(runs []*platform.Run) error {
}
}

if !foundWorker {
return errors.New("worker not found to resume work")
}
}

if !foundWorker {
return errors.New("worker not found to resume work")
}

return nil
Expand Down

0 comments on commit 10bfc91

Please sign in to comment.