diff options
Diffstat (limited to 'makima/src/db/repository.rs')
| -rw-r--r-- | makima/src/db/repository.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index a79818f..51f49cd 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -5298,6 +5298,30 @@ pub async fn get_completed_step_tasks( .await } +/// Get the task ID of the most recently completed step for a directive. +/// Used as a fallback `continue_from_task_id` when dispatching new-generation steps +/// that have no explicit dependencies and no PR branch to continue from. +pub async fn get_last_completed_step_task_id( + pool: &PgPool, + directive_id: Uuid, +) -> Result<Option<Uuid>, sqlx::Error> { + let row: Option<(Uuid,)> = sqlx::query_as( + r#" + SELECT ds.task_id + FROM directive_steps ds + WHERE ds.directive_id = $1 + AND ds.status = 'completed' + AND ds.task_id IS NOT NULL + ORDER BY ds.updated_at DESC + LIMIT 1 + "#, + ) + .bind(directive_id) + .fetch_optional(pool) + .await?; + Ok(row.map(|r| r.0)) +} + // ============================================================================= // Directive Step CRUD // ============================================================================= @@ -5586,6 +5610,8 @@ pub struct StepForDispatch { pub repository_url: Option<String>, pub base_branch: Option<String>, pub memory_enabled: bool, + /// The directive's PR branch (if a PR has already been created from previous steps). + pub pr_branch: Option<String>, } /// Get ready steps that need task dispatch. @@ -5607,7 +5633,8 @@ pub async fn get_ready_steps_for_dispatch( d.title AS directive_title, d.repository_url, d.base_branch, - d.memory_enabled + d.memory_enabled, + d.pr_branch FROM directive_steps ds JOIN directives d ON d.id = ds.directive_id WHERE ds.status = 'ready' |
