fix(store): a restart re-queues a running task at its interrupted step and parks it after 3 restarts (#1841)
This commit is contained in:
11 files changed
+338
-62
No files matched your search
@@ -356,3 +356,56 @@ func TransientRetryDue(class string, retries int, parkedAt, now time.Time) bool
|
||||
}
|
||||
return !now.Before(parkedAt.Add(transientBackoffBase << retries))
|
||||
}
|
||||
|
||||
// MaxRestartRequeues is how many times daemon restarts may re-queue a task
|
||||
// that was running before it parks for an operator.
|
||||
const MaxRestartRequeues = 3
|
||||
|
||||
// RecoveryInput is what the store knows about a task a restart found running.
|
||||
type RecoveryInput struct {
|
||||
// Restarts is how many earlier restarts re-queued the task.
|
||||
Restarts int
|
||||
// Stage is the root step the restart interrupted, "" when none was running.
|
||||
Stage string
|
||||
// PriorResults are the step results recorded by the last step this attempt
|
||||
// finished before Stage, nil when it finished none.
|
||||
PriorResults []byte
|
||||
// RetryMode, ResumeFrom and ResumeResults are the task row's own.
|
||||
RetryMode, ResumeFrom string
|
||||
ResumeResults []byte
|
||||
}
|
||||
|
||||
// Recovery is how a task a restart found running continues.
|
||||
type Recovery struct {
|
||||
// Park reports that the task goes to an operator instead of the queue.
|
||||
Park bool
|
||||
ParkReason string
|
||||
// RetryMode, ResumeFrom and ResumeResults are written to the re-queued row.
|
||||
RetryMode, ResumeFrom string
|
||||
ResumeResults []byte
|
||||
}
|
||||
|
||||
// PlanRecovery decides how a restart treats a task left running: it resumes
|
||||
// at the interrupted step in its kept worktree, with the results of the steps
|
||||
// before it, rather than repaying them. A task already re-queued
|
||||
// MaxRestartRequeues times parks instead.
|
||||
func PlanRecovery(in RecoveryInput) Recovery {
|
||||
if in.Restarts >= MaxRestartRequeues {
|
||||
return Recovery{Park: true, ParkReason: fmt.Sprintf("interrupted by %d daemon restarts in a row; retry to run it again", in.Restarts)}
|
||||
}
|
||||
rec := Recovery{RetryMode: in.RetryMode, ResumeFrom: in.ResumeFrom, ResumeResults: in.ResumeResults}
|
||||
if in.Stage == "" {
|
||||
return rec
|
||||
}
|
||||
switch {
|
||||
case in.PriorResults != nil:
|
||||
rec.ResumeFrom, rec.ResumeResults = in.Stage, in.PriorResults
|
||||
case in.ResumeFrom == in.Stage:
|
||||
// The attempt was itself resumed at this step and finished none since.
|
||||
default:
|
||||
// The first step of a fresh attempt: nothing is finished, so start over.
|
||||
return Recovery{RetryMode: in.RetryMode, ResumeResults: []byte("{}")}
|
||||
}
|
||||
rec.RetryMode = string(RetryKeepWorktree)
|
||||
return rec
|
||||
}
|
||||
Reference in new issue
Block a user