agent_orchestrator/task_repository/
trait_def.rs1use crate::dto::{TaskGraphDebugBundle, TaskItemRow, TaskSummary};
2use anyhow::Result;
3
4use super::TaskDetailRows;
5use super::command_run::NewCommandRun;
6use super::types::{DbEventRecord, TaskLogRunRow, TaskRuntimeRow};
7
8pub trait TaskRepository {
10 fn resolve_task_id(&self, task_id_or_prefix: &str) -> Result<String>;
12 fn load_task_summary(&self, task_id: &str) -> Result<TaskSummary>;
14 fn load_task_detail_rows(&self, task_id: &str) -> Result<TaskDetailRows>;
16 fn load_task_item_counts(&self, task_id: &str) -> Result<(i64, i64, i64)>;
18 fn list_task_ids_ordered_by_created_desc(&self) -> Result<Vec<String>>;
20 fn find_latest_resumable_task_id(&self, include_pending: bool) -> Result<Option<String>>;
22 fn load_task_runtime_row(&self, task_id: &str) -> Result<TaskRuntimeRow>;
24 fn first_task_item_id(&self, task_id: &str) -> Result<Option<String>>;
26 fn count_unresolved_items(&self, task_id: &str) -> Result<i64>;
28 fn list_task_items_for_cycle(&self, task_id: &str) -> Result<Vec<TaskItemRow>>;
30 fn load_task_status(&self, task_id: &str) -> Result<Option<String>>;
32 fn set_task_status(&self, task_id: &str, status: &str, set_completed: bool) -> Result<()>;
34 fn prepare_task_for_start_batch(&self, task_id: &str) -> Result<()>;
36 fn update_task_cycle_state(
38 &self,
39 task_id: &str,
40 current_cycle: u32,
41 init_done: bool,
42 ) -> Result<()>;
43 fn mark_task_item_running(&self, task_item_id: &str) -> Result<()>;
45 fn set_task_item_terminal_status(&self, task_item_id: &str, status: &str) -> Result<()>;
47 fn update_task_item_status(&self, task_item_id: &str, status: &str) -> Result<()>;
49 fn update_task_item_pipeline_vars(
51 &self,
52 task_item_id: &str,
53 pipeline_vars_json: &str,
54 ) -> Result<()>;
55 fn load_task_name(&self, task_id: &str) -> Result<Option<String>>;
57 fn list_task_log_runs(&self, task_id: &str, limit: usize) -> Result<Vec<TaskLogRunRow>>;
59 fn insert_task_graph_run(&self, run: &super::types::NewTaskGraphRun) -> Result<()>;
61 fn update_task_graph_run_status(&self, graph_run_id: &str, status: &str) -> Result<()>;
63 fn insert_task_graph_snapshot(
65 &self,
66 snapshot: &super::types::NewTaskGraphSnapshot,
67 ) -> Result<()>;
68 fn load_task_graph_debug_bundles(&self, task_id: &str) -> Result<Vec<TaskGraphDebugBundle>>;
70 fn delete_task_and_collect_log_paths(&self, task_id: &str) -> Result<Vec<String>>;
72 fn insert_command_run(&self, run: &NewCommandRun) -> Result<()>;
74 fn insert_event(&self, event: &DbEventRecord) -> Result<()>;
76 fn update_command_run(&self, run: &NewCommandRun) -> Result<()>;
78 fn update_command_run_with_events(
80 &self,
81 run: &NewCommandRun,
82 events: &[DbEventRecord],
83 ) -> Result<()>;
84 fn persist_phase_result_with_events(
86 &self,
87 run: &NewCommandRun,
88 events: &[DbEventRecord],
89 ) -> Result<()>;
90 fn update_command_run_pid(&self, run_id: &str, pid: i64) -> Result<()>;
92 fn find_active_child_pids(&self, task_id: &str) -> Result<Vec<i64>>;
94 fn find_inflight_command_runs_for_task(
96 &self,
97 task_id: &str,
98 ) -> Result<Vec<super::write_ops::InflightRunRecord>>;
99 fn find_completed_runs_for_pending_items(
101 &self,
102 task_id: &str,
103 ) -> Result<Vec<super::write_ops::CompletedRunRecord>>;
104 fn count_stale_pending_items(&self, task_id: &str) -> Result<i64>;
106 fn count_recent_heartbeats_for_items(
108 &self,
109 task_id: &str,
110 item_ids: &[String],
111 cutoff_ts: &str,
112 ) -> Result<i64>;
113 fn update_task_pipeline_vars(&self, task_id: &str, pipeline_vars_json: &str) -> Result<()>;
115 fn update_task_item_tickets(
117 &self,
118 task_item_id: &str,
119 ticket_files_json: &str,
120 ticket_content_json: &str,
121 ) -> Result<()>;
122}