summaryrefslogtreecommitdiff
path: root/internal/executor/executor.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/executor/executor.go')
-rw-r--r--internal/executor/executor.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/executor/executor.go b/internal/executor/executor.go
index 440294c..22273d9 100644
--- a/internal/executor/executor.go
+++ b/internal/executor/executor.go
@@ -33,6 +33,9 @@ type Store interface {
UpdateExecutionChangestats(execID string, stats *task.Changestats) error
RecordAgentEvent(e storage.AgentEvent) error
GetProject(id string) (*task.Project, error)
+ GetStory(id string) (*task.Story, error)
+ ListTasksByStory(storyID string) ([]*task.Task, error)
+ UpdateStoryStatus(id string, status task.StoryState) error
}
// LogPather is an optional interface runners can implement to provide the log
@@ -399,6 +402,9 @@ func (p *Pool) handleRunResult(ctx context.Context, t *task.Task, exec *storage.
}
p.maybeUnblockParent(t.ParentTaskID)
}
+ if t.StoryID != "" {
+ go p.checkStoryCompletion(ctx, t.StoryID)
+ }
}
summary := exec.Summary
@@ -430,6 +436,29 @@ func (p *Pool) handleRunResult(ctx context.Context, t *task.Task, exec *storage.
p.resultCh <- &Result{TaskID: t.ID, Execution: exec, Err: err}
}
+// checkStoryCompletion checks whether all tasks in a story have reached a terminal
+// success state and transitions the story to SHIPPABLE if so.
+func (p *Pool) checkStoryCompletion(ctx context.Context, storyID string) {
+ tasks, err := p.store.ListTasksByStory(storyID)
+ if err != nil {
+ p.logger.Error("checkStoryCompletion: failed to list tasks", "storyID", storyID, "error", err)
+ return
+ }
+ if len(tasks) == 0 {
+ return
+ }
+ for _, t := range tasks {
+ if t.State != task.StateCompleted && t.State != task.StateReady {
+ return // not all tasks done
+ }
+ }
+ if err := p.store.UpdateStoryStatus(storyID, task.StoryShippable); err != nil {
+ p.logger.Error("checkStoryCompletion: failed to update story status", "storyID", storyID, "error", err)
+ return
+ }
+ p.logger.Info("story transitioned to SHIPPABLE", "storyID", storyID)
+}
+
// UndrainingAgent resets the drain state and failure counter for the given agent type.
func (p *Pool) UndrainingAgent(agentType string) {
p.mu.Lock()