feat(taskactions): retry a parked task on the current workflow definition
This commit is contained in:
1 parent
c80d4750a8
commit
9d7287c647
18 files changed
+134
-58
No files matched your search
@@ -97,15 +97,16 @@ func (c *Client) ApplyTaskAction(ctx context.Context, identity string, taskID in
|
||||
|
||||
func (c *Client) ApplyOperatorTaskAction(ctx context.Context, actor taskactions.Actor, taskID int64, action taskstate.Action, res taskactions.ActionPayload) (messaging.TaskActionResult, error) {
|
||||
v, err := c.client.ApplyOperatorTaskAction(ctx, &pb.ApplyOperatorTaskActionRequest{
|
||||
TaskId: taskID,
|
||||
Action: string(action),
|
||||
ActorId: string(actor.Identity),
|
||||
ActorKind: string(actor.Kind),
|
||||
PrincipalId: string(actor.Principal),
|
||||
Instructions: res.Instructions,
|
||||
Findings: res.Findings,
|
||||
RetryMode: string(res.RetryMode),
|
||||
ResumeFrom: res.ResumeFrom,
|
||||
TaskId: taskID,
|
||||
Action: string(action),
|
||||
ActorId: string(actor.Identity),
|
||||
ActorKind: string(actor.Kind),
|
||||
PrincipalId: string(actor.Principal),
|
||||
Instructions: res.Instructions,
|
||||
Findings: res.Findings,
|
||||
RetryMode: string(res.RetryMode),
|
||||
ResumeFrom: res.ResumeFrom,
|
||||
CurrentDefinition: res.CurrentDefinition,
|
||||
})
|
||||
if err != nil {
|
||||
return messaging.TaskActionResult{}, taskActionError(err)
|
||||
|
||||
@@ -116,10 +116,11 @@ func (s *server) ApplyOperatorTaskAction(ctx context.Context, r *pb.ApplyOperato
|
||||
Principal: identity.IdentityID(r.PrincipalId),
|
||||
}
|
||||
v, err := s.chat.ApplyOperatorTaskAction(ctx, actor, r.TaskId, taskstate.Action(r.Action), taskactions.ActionPayload{
|
||||
Instructions: r.Instructions,
|
||||
Findings: r.Findings,
|
||||
RetryMode: taskstate.RetryMode(r.RetryMode),
|
||||
ResumeFrom: r.ResumeFrom,
|
||||
Instructions: r.Instructions,
|
||||
Findings: r.Findings,
|
||||
RetryMode: taskstate.RetryMode(r.RetryMode),
|
||||
ResumeFrom: r.ResumeFrom,
|
||||
CurrentDefinition: r.CurrentDefinition,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, taskActionStatus(err)
|
||||
|
||||
@@ -890,17 +890,21 @@ UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
||||
retry_mode = $2::text,
|
||||
resume_from = $3::text, resume_results = $4::jsonb,
|
||||
workflow_definition_yaml = CASE WHEN $5::bool THEN '' ELSE workflow_definition_yaml END,
|
||||
workflow_definition_digest = CASE WHEN $5::bool THEN '' ELSE workflow_definition_digest END,
|
||||
workflow_definition_version = CASE WHEN $5::bool THEN 0 ELSE workflow_definition_version END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = $5 AND status = $6
|
||||
WHERE id = $6 AND status = $7
|
||||
`
|
||||
|
||||
type RetryTaskParams struct {
|
||||
Workflow string
|
||||
RetryMode string
|
||||
ResumeFrom string
|
||||
ResumeResults []byte
|
||||
ID int64
|
||||
FromStatus string
|
||||
Workflow string
|
||||
RetryMode string
|
||||
ResumeFrom string
|
||||
ResumeResults []byte
|
||||
CurrentDefinition bool
|
||||
ID int64
|
||||
FromStatus string
|
||||
}
|
||||
|
||||
func (q *Queries) RetryTask(ctx context.Context, arg RetryTaskParams) (int64, error) {
|
||||
@@ -909,6 +913,7 @@ func (q *Queries) RetryTask(ctx context.Context, arg RetryTaskParams) (int64, er
|
||||
arg.RetryMode,
|
||||
arg.ResumeFrom,
|
||||
arg.ResumeResults,
|
||||
arg.CurrentDefinition,
|
||||
arg.ID,
|
||||
arg.FromStatus,
|
||||
)
|
||||
|
||||
@@ -258,6 +258,9 @@ UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
||||
workflow = CASE WHEN @workflow::text = '' THEN workflow ELSE @workflow::text END,
|
||||
retry_mode = @retry_mode::text,
|
||||
resume_from = @resume_from::text, resume_results = @resume_results::jsonb,
|
||||
workflow_definition_yaml = CASE WHEN @current_definition::bool THEN '' ELSE workflow_definition_yaml END,
|
||||
workflow_definition_digest = CASE WHEN @current_definition::bool THEN '' ELSE workflow_definition_digest END,
|
||||
workflow_definition_version = CASE WHEN @current_definition::bool THEN 0 ELSE workflow_definition_version END,
|
||||
park_reason = '', park_class = 'needs_human', updated_at = now()
|
||||
WHERE id = @id AND status = @from_status;
|
||||
|
||||
|
||||
@@ -535,9 +535,11 @@ func (s *Store) Requeue(ctx context.Context, taskID int64, fromStatus, wf string
|
||||
// transaction, under the same table check Requeue applies. retryMode is the
|
||||
// operator's worktree choice for the next dispatch; the store persists it
|
||||
// unread so the daemon's prepareWorkspace reads the mode the operator set.
|
||||
// currentDefinition clears the pinned definition so the next dispatch pins
|
||||
// the workflow's current stored version.
|
||||
// A resume copies the results recorded after its After stage onto the row, in
|
||||
// the same transaction, so the attempt starts from what that stage left.
|
||||
func (s *Store) RetryTask(ctx context.Context, taskID int64, fromStatus, wf, retryMode string, resume task.Resume) error {
|
||||
func (s *Store) RetryTask(ctx context.Context, taskID int64, fromStatus, wf, retryMode string, resume task.Resume, currentDefinition bool) error {
|
||||
return s.requeue(ctx, taskID, fromStatus, wf, "retried "+wf, func(q *postgresdb.Queries) (int64, error) {
|
||||
results, err := resumeResults(ctx, q, taskID, resume)
|
||||
if err != nil {
|
||||
@@ -545,7 +547,7 @@ func (s *Store) RetryTask(ctx context.Context, taskID int64, fromStatus, wf, ret
|
||||
}
|
||||
return q.RetryTask(ctx, postgresdb.RetryTaskParams{
|
||||
ID: taskID, Workflow: wf, FromStatus: fromStatus, RetryMode: retryMode,
|
||||
ResumeFrom: resume.From, ResumeResults: results,
|
||||
ResumeFrom: resume.From, ResumeResults: results, CurrentDefinition: currentDefinition,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -260,10 +260,10 @@ func (c *Client) ArchiveTask(ctx context.Context, taskID int64, fromStatus strin
|
||||
return r.EventId, nil
|
||||
}
|
||||
|
||||
func (c *Client) RetryTask(ctx context.Context, taskID int64, fromStatus, wf, retryMode string, resume task.Resume) error {
|
||||
func (c *Client) RetryTask(ctx context.Context, taskID int64, fromStatus, wf, retryMode string, resume task.Resume, currentDefinition bool) error {
|
||||
_, err := c.client.RetryTask(ctx, &pb.RetryTaskRequest{
|
||||
TaskId: taskID, FromStatus: fromStatus, Workflow: wf, RetryMode: retryMode,
|
||||
ResumeFrom: resume.From, ResumeAfter: resume.After,
|
||||
ResumeFrom: resume.From, ResumeAfter: resume.After, CurrentDefinition: currentDefinition,
|
||||
})
|
||||
return unmapError(err)
|
||||
}
|
||||
|
||||
@@ -458,7 +458,7 @@ func (s *server) ArchiveTask(ctx context.Context, r *pb.ArchiveTaskRequest) (*pb
|
||||
}
|
||||
|
||||
func (s *server) RetryTask(ctx context.Context, r *pb.RetryTaskRequest) (*pb.RetryTaskResponse, error) {
|
||||
if err := s.deps.Tasks.RetryTask(ctx, r.TaskId, r.FromStatus, r.Workflow, r.RetryMode, task.Resume{From: r.ResumeFrom, After: r.ResumeAfter}); err != nil {
|
||||
if err := s.deps.Tasks.RetryTask(ctx, r.TaskId, r.FromStatus, r.Workflow, r.RetryMode, task.Resume{From: r.ResumeFrom, After: r.ResumeAfter}, r.CurrentDefinition); err != nil {
|
||||
return nil, s.logErr("RetryTask", err)
|
||||
}
|
||||
return &pb.RetryTaskResponse{}, nil
|
||||
|
||||
@@ -36,6 +36,8 @@ type actionRequest struct {
|
||||
Findings []string `json:"findings,omitempty"`
|
||||
RetryMode taskstate.RetryMode `json:"retry_mode,omitempty"`
|
||||
ResumeFrom string `json:"resume_from,omitempty"`
|
||||
// CurrentDefinition moves a retry onto the current stored definition.
|
||||
CurrentDefinition bool `json:"current_definition,omitempty"`
|
||||
}
|
||||
|
||||
type actorPayload struct {
|
||||
@@ -118,10 +120,11 @@ func Register(nc *nats.Conn, service taskactions.Service, log *slog.Logger) (fun
|
||||
return
|
||||
}
|
||||
err := service.Apply(context.Background(), req.Identity, req.Actor.actor(), req.TaskID, req.Action, taskactions.ActionPayload{
|
||||
Instructions: req.Instructions,
|
||||
Findings: req.Findings,
|
||||
RetryMode: req.RetryMode,
|
||||
ResumeFrom: req.ResumeFrom,
|
||||
Instructions: req.Instructions,
|
||||
Findings: req.Findings,
|
||||
RetryMode: req.RetryMode,
|
||||
ResumeFrom: req.ResumeFrom,
|
||||
CurrentDefinition: req.CurrentDefinition,
|
||||
})
|
||||
natsrpc.Respond(msg, log, "taskactions", actionResponse{
|
||||
Envelope: natsrpc.NewEnvelope(err),
|
||||
@@ -149,13 +152,14 @@ func (c Client) ApplyChatTaskAction(ctx context.Context, scope *string, actor ta
|
||||
return gateway.TaskActionResult{}, fmt.Errorf("task action connection is unavailable")
|
||||
}
|
||||
request := actionRequest{
|
||||
Identity: scope,
|
||||
TaskID: id,
|
||||
Action: action,
|
||||
Instructions: res.Instructions,
|
||||
Findings: res.Findings,
|
||||
RetryMode: res.RetryMode,
|
||||
ResumeFrom: res.ResumeFrom,
|
||||
Identity: scope,
|
||||
TaskID: id,
|
||||
Action: action,
|
||||
Instructions: res.Instructions,
|
||||
Findings: res.Findings,
|
||||
RetryMode: res.RetryMode,
|
||||
ResumeFrom: res.ResumeFrom,
|
||||
CurrentDefinition: res.CurrentDefinition,
|
||||
Actor: &actorPayload{
|
||||
ID: string(actor.Identity),
|
||||
Kind: string(actor.Kind),
|
||||
|
||||
Reference in new issue
Block a user