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
@@ -121,7 +121,7 @@ const interruptAttemptSteps = `-- name: InterruptAttemptSteps :many
|
||||
UPDATE step_executions
|
||||
SET status = 'interrupted', finished_at = now()
|
||||
WHERE execution_id = $1 AND attempt = $2 AND status = 'running'
|
||||
RETURNING id, name
|
||||
RETURNING id, name, depth, kind
|
||||
`
|
||||
|
||||
type InterruptAttemptStepsParams struct {
|
||||
@@ -130,8 +130,10 @@ type InterruptAttemptStepsParams struct {
|
||||
}
|
||||
|
||||
type InterruptAttemptStepsRow struct {
|
||||
ID int64
|
||||
Name string
|
||||
ID int64
|
||||
Name string
|
||||
Depth int32
|
||||
Kind string
|
||||
}
|
||||
|
||||
// The crash-recovery step edge (docs/prds/execution-tree-state-machine.md):
|
||||
@@ -148,7 +150,12 @@ func (q *Queries) InterruptAttemptSteps(ctx context.Context, arg InterruptAttemp
|
||||
var items []InterruptAttemptStepsRow
|
||||
for rows.Next() {
|
||||
var i InterruptAttemptStepsRow
|
||||
if err := rows.Scan(&i.ID, &i.Name); err != nil {
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Depth,
|
||||
&i.Kind,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
@@ -299,19 +306,24 @@ func (q *Queries) LockExecutionForStep(ctx context.Context, id int64) (LockExecu
|
||||
}
|
||||
|
||||
const lockRunningExecutions = `-- name: LockRunningExecutions :many
|
||||
SELECT id, org_id, workspace_id, owner, repo, issue_number, workflow, attempt
|
||||
SELECT id, org_id, workspace_id, owner, repo, issue_number, workflow, attempt,
|
||||
restart_requeues, retry_mode, resume_from, resume_results
|
||||
FROM tasks WHERE status = 'running' FOR UPDATE
|
||||
`
|
||||
|
||||
type LockRunningExecutionsRow struct {
|
||||
ID int64
|
||||
OrgID string
|
||||
WorkspaceID string
|
||||
Owner string
|
||||
Repo string
|
||||
IssueNumber int64
|
||||
Workflow string
|
||||
Attempt int64
|
||||
ID int64
|
||||
OrgID string
|
||||
WorkspaceID string
|
||||
Owner string
|
||||
Repo string
|
||||
IssueNumber int64
|
||||
Workflow string
|
||||
Attempt int64
|
||||
RestartRequeues int64
|
||||
RetryMode string
|
||||
ResumeFrom string
|
||||
ResumeResults []byte
|
||||
}
|
||||
|
||||
// The executions a crashed or replaced daemon left running, locked for the
|
||||
@@ -335,6 +347,10 @@ func (q *Queries) LockRunningExecutions(ctx context.Context) ([]LockRunningExecu
|
||||
&i.IssueNumber,
|
||||
&i.Workflow,
|
||||
&i.Attempt,
|
||||
&i.RestartRequeues,
|
||||
&i.RetryMode,
|
||||
&i.ResumeFrom,
|
||||
&i.ResumeResults,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -395,6 +411,29 @@ func (q *Queries) LockStepExecution(ctx context.Context, id int64) (LockStepExec
|
||||
return i, err
|
||||
}
|
||||
|
||||
const priorStageResults = `-- name: PriorStageResults :one
|
||||
SELECT results FROM step_executions
|
||||
WHERE execution_id = $1 AND attempt = $2 AND id < $3 AND depth = 0 AND kind = 'stage'
|
||||
AND status IN ('succeeded', 'failed', 'skipped') AND results IS NOT NULL
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type PriorStageResultsParams struct {
|
||||
ExecutionID int64
|
||||
Attempt int64
|
||||
ID int64
|
||||
}
|
||||
|
||||
// What the attempt's last finished root stage before the given step recorded,
|
||||
// the results a restart resumes that step with.
|
||||
func (q *Queries) PriorStageResults(ctx context.Context, arg PriorStageResultsParams) ([]byte, error) {
|
||||
row := q.db.QueryRow(ctx, priorStageResults, arg.ExecutionID, arg.Attempt, arg.ID)
|
||||
var results []byte
|
||||
err := row.Scan(&results)
|
||||
return results, err
|
||||
}
|
||||
|
||||
const startStepExecution = `-- name: StartStepExecution :execrows
|
||||
UPDATE step_executions SET status = 'running', started_at = now()
|
||||
WHERE id = $1 AND status = 'pending'
|
||||
|
||||
Reference in new issue
Block a user