1use pe_core::PeError;
8
9use crate::dependency::TaskDependency;
10use crate::task::{Task, TaskId, TaskPriority, TaskStatus, TaskType};
11
12#[async_trait::async_trait]
17pub trait TaskRegistry: Send + Sync {
18 async fn create(&self, task: Task) -> Result<Task, PeError>;
22
23 async fn get(&self, id: &TaskId) -> Result<Option<Task>, PeError>;
25
26 async fn update(&self, task: &Task) -> Result<Task, PeError>;
28
29 async fn delete(&self, id: &TaskId) -> Result<bool, PeError>;
31
32 async fn restore(&self, id: &TaskId) -> Result<bool, PeError>;
34
35 async fn update_status(
39 &self,
40 id: &TaskId,
41 status: TaskStatus,
42 result: Option<serde_json::Value>,
43 error: Option<String>,
44 ) -> Result<Task, PeError>;
45
46 async fn list(&self, filter: &TaskFilter) -> Result<Vec<Task>, PeError>;
50
51 async fn get_subtasks(&self, parent_id: &TaskId) -> Result<Vec<Task>, PeError>;
53
54 async fn get_tree(&self, root_id: &TaskId) -> Result<Vec<Task>, PeError>;
56
57 async fn add_dependency(&self, dep: TaskDependency) -> Result<(), PeError>;
61
62 async fn remove_dependency(
64 &self,
65 task_id: &TaskId,
66 depends_on_id: &TaskId,
67 ) -> Result<(), PeError>;
68
69 async fn get_dependencies(&self, task_id: &TaskId) -> Result<Vec<TaskDependency>, PeError>;
71
72 async fn get_dependents(&self, task_id: &TaskId) -> Result<Vec<TaskDependency>, PeError>;
74
75 async fn get_ready_tasks(&self) -> Result<Vec<Task>, PeError>;
77}
78
79#[derive(Clone, Debug, Default)]
92pub struct TaskFilter {
93 pub status: Option<TaskStatus>,
94 pub task_type: Option<TaskType>,
95 pub priority: Option<TaskPriority>,
96 pub agent_id: Option<String>,
97 pub assignee: Option<String>,
98 pub parent_id: Option<TaskId>,
99 pub tag: Option<String>,
100 pub include_deleted: bool,
101 pub limit: usize,
102}
103
104impl TaskFilter {
105 #[must_use]
107 pub fn with_status(mut self, status: TaskStatus) -> Self {
108 self.status = Some(status);
109 self
110 }
111
112 #[must_use]
114 pub fn with_task_type(mut self, tt: TaskType) -> Self {
115 self.task_type = Some(tt);
116 self
117 }
118
119 #[must_use]
121 pub fn with_priority(mut self, priority: TaskPriority) -> Self {
122 self.priority = Some(priority);
123 self
124 }
125
126 #[must_use]
128 pub fn with_agent(mut self, agent_id: impl Into<String>) -> Self {
129 self.agent_id = Some(agent_id.into());
130 self
131 }
132
133 #[must_use]
135 pub fn with_assignee(mut self, assignee: impl Into<String>) -> Self {
136 self.assignee = Some(assignee.into());
137 self
138 }
139
140 #[must_use]
142 pub fn with_parent(mut self, parent_id: impl Into<TaskId>) -> Self {
143 self.parent_id = Some(parent_id.into());
144 self
145 }
146
147 #[must_use]
149 pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
150 self.tag = Some(tag.into());
151 self
152 }
153
154 #[must_use]
156 pub fn with_limit(mut self, limit: usize) -> Self {
157 self.limit = limit;
158 self
159 }
160
161 #[must_use]
163 pub fn including_deleted(mut self) -> Self {
164 self.include_deleted = true;
165 self
166 }
167}