Run each workflow stage as its own task, with fan-out and fan-in
This commit is contained in:
+32
-18
@@ -357,6 +357,18 @@ UPDATE workflows SET definition = json_set(definition, '$.stages',
|
||||
UPDATE tasks SET workflow_definition = json_set(workflow_definition, '$.stages',
|
||||
(SELECT json_group_array(json_remove(value, '$.vendor')) FROM (SELECT value FROM json_each(workflow_definition, '$.stages') ORDER BY key)))
|
||||
WHERE workflow_definition != '';
|
||||
`}, {"workflow-stage-tasks", `
|
||||
ALTER TABLE tasks ADD COLUMN workflow_run TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE tasks ADD COLUMN workflow_stage TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE tasks ADD COLUMN workflow_title TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE tasks ADD COLUMN stage_output TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE tasks ADD COLUMN stage_commit TEXT NOT NULL DEFAULT '';
|
||||
UPDATE tasks SET workflow_run = id, workflow_title = title,
|
||||
workflow_stage = coalesce(
|
||||
(SELECT json_extract(tasks.workflow_definition, '$.stages[' || (s.workflow_stage - 1) || '].name') FROM agent_sessions s
|
||||
WHERE s.task_id = tasks.id AND s.workflow_stage > 0 ORDER BY s.created_at DESC LIMIT 1),
|
||||
json_extract(workflow_definition, '$.stages[0].name'))
|
||||
WHERE workflow_name != '' AND workflow_run = '';
|
||||
`}}
|
||||
|
||||
const (
|
||||
@@ -626,6 +638,9 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, frozen *FrozenWorkfl
|
||||
workflowName := ""
|
||||
workflowDefinition := ""
|
||||
workflowBrief := ""
|
||||
workflowTitle := ""
|
||||
workflowRun := ""
|
||||
workflowStage := ""
|
||||
if frozen != nil {
|
||||
b, err := json.Marshal(frozen.Definition)
|
||||
if err != nil {
|
||||
@@ -634,6 +649,9 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, frozen *FrozenWorkfl
|
||||
workflowName = frozen.Name
|
||||
workflowDefinition = string(b)
|
||||
workflowBrief = frozen.Brief
|
||||
workflowTitle = frozen.Title
|
||||
workflowRun = *t.WorkflowRun
|
||||
workflowStage = *t.WorkflowStage
|
||||
t.Workflow = &workflowName
|
||||
}
|
||||
todoItem := ""
|
||||
@@ -672,9 +690,9 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, frozen *FrozenWorkfl
|
||||
return err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO tasks (id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, todo_item, forked_from, forked_at, workflow_name, workflow_definition, workflow_brief)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, mergeTitle, t.Branch, t.WorktreePath, t.BaseRef, t.PortBase, t.Color, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem, forkedFrom, forkedAt, workflowName, workflowDefinition, workflowBrief)
|
||||
INSERT INTO tasks (id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, todo_item, forked_from, forked_at, workflow_name, workflow_definition, workflow_brief, workflow_title, workflow_run, workflow_stage)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, mergeTitle, t.Branch, t.WorktreePath, t.BaseRef, t.PortBase, t.Color, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem, forkedFrom, forkedAt, workflowName, workflowDefinition, workflowBrief, workflowTitle, workflowRun, workflowStage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1017,15 +1035,11 @@ func (s *Store) CreateSession(ctx context.Context, sess api.AgentSession, projec
|
||||
forkedFrom = *sess.ForkedFrom
|
||||
forkedAt = *sess.ForkedAt
|
||||
}
|
||||
stage := 0
|
||||
if sess.WorkflowStage != nil {
|
||||
stage = *sess.WorkflowStage
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
INSERT INTO agent_sessions (id, task_id, owner, vendor, model, vendor_session_id, state, role, created_by, created_at, forked_from, forked_at, workflow_stage)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, sess.Id, nullable(sess.TaskId), sess.Owner, string(sess.Vendor), sess.Model, sess.VendorSessionId, string(sess.State), string(sess.Role), sess.CreatedBy, formatTime(sess.CreatedAt), forkedFrom, forkedAt, stage)
|
||||
INSERT INTO agent_sessions (id, task_id, owner, vendor, model, vendor_session_id, state, role, created_by, created_at, forked_from, forked_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, sess.Id, nullable(sess.TaskId), sess.Owner, string(sess.Vendor), sess.Model, sess.VendorSessionId, string(sess.State), string(sess.Role), sess.CreatedBy, formatTime(sess.CreatedAt), forkedFrom, forkedAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1264,9 +1278,9 @@ func (s *Store) write(ctx context.Context, fn func(tx *sql.Tx, emit emitFunc) er
|
||||
|
||||
const projectColumns = `id, name, repo_path, default_branch, remote, created_by, created_at`
|
||||
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, closed_at, merge_commit, todo_item, forked_from, forked_at, merge_queued_at, workflow_name`
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, closed_at, merge_commit, todo_item, forked_from, forked_at, merge_queued_at, workflow_name, workflow_run, workflow_stage`
|
||||
|
||||
const sessionColumns = `id, coalesce(task_id, ''), owner, vendor, model, vendor_session_id, state, role, created_by, created_at, forked_from, forked_at, workflow_stage`
|
||||
const sessionColumns = `id, coalesce(task_id, ''), owner, vendor, model, vendor_session_id, state, role, created_by, created_at, forked_from, forked_at`
|
||||
|
||||
type scanner interface {
|
||||
Scan(dest ...any) error
|
||||
@@ -1294,12 +1308,16 @@ func scanTask(row scanner) (api.Task, error) {
|
||||
forkedAt := 0
|
||||
mergeQueuedAt := ""
|
||||
workflowName := ""
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &t.PortBase, &t.Color, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem, &forkedFrom, &forkedAt, &mergeQueuedAt, &workflowName)
|
||||
workflowRun := ""
|
||||
workflowStage := ""
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &t.PortBase, &t.Color, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem, &forkedFrom, &forkedAt, &mergeQueuedAt, &workflowName, &workflowRun, &workflowStage)
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
if workflowName != "" {
|
||||
t.Workflow = &workflowName
|
||||
t.WorkflowRun = &workflowRun
|
||||
t.WorkflowStage = &workflowStage
|
||||
}
|
||||
if t.MergeTitle == "" {
|
||||
t.MergeTitle = t.Title
|
||||
@@ -1344,14 +1362,10 @@ func scanSession(row scanner) (api.AgentSession, error) {
|
||||
createdAt := ""
|
||||
forkedFrom := ""
|
||||
forkedAt := ""
|
||||
stage := 0
|
||||
err := row.Scan(&sess.Id, &sess.TaskId, &sess.Owner, &vendor, &sess.Model, &sess.VendorSessionId, &state, &role, &sess.CreatedBy, &createdAt, &forkedFrom, &forkedAt, &stage)
|
||||
err := row.Scan(&sess.Id, &sess.TaskId, &sess.Owner, &vendor, &sess.Model, &sess.VendorSessionId, &state, &role, &sess.CreatedBy, &createdAt, &forkedFrom, &forkedAt)
|
||||
if err != nil {
|
||||
return sess, err
|
||||
}
|
||||
if stage > 0 {
|
||||
sess.WorkflowStage = &stage
|
||||
}
|
||||
if forkedFrom != "" {
|
||||
sess.ForkedFrom = &forkedFrom
|
||||
sess.ForkedAt = &forkedAt
|
||||
|
||||
Reference in New Issue
Block a user