diff options
Diffstat (limited to 'internal/executor/executor.go')
| -rw-r--r-- | internal/executor/executor.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 6489060..8dfb196 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -34,6 +34,8 @@ type Store interface { 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 @@ -406,6 +408,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 @@ -437,6 +442,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() |
