Retry a task by creating a new task with the same instructions. Creates a duplicate task with a new ID, optionally allowing instruction editing. The original task must have been executed (not Queued) to be retried.
(
&self,
task_id: &str,
edit_instructions: bool,
overrides: RetryOverrides,
ctx: &AppContext,
)
| 182 | /// Creates a duplicate task with a new ID, optionally allowing instruction editing. |
| 183 | /// The original task must have been executed (not Queued) to be retried. |
| 184 | pub async fn retry_task( |
| 185 | &self, |
| 186 | task_id: &str, |
| 187 | edit_instructions: bool, |
| 188 | overrides: RetryOverrides, |
| 189 | ctx: &AppContext, |
| 190 | ) -> Result<String, String> { |
| 191 | // Retrieve the original task |
| 192 | let original_task = self |
| 193 | .task_storage |
| 194 | .get_task(task_id) |
| 195 | .await |
| 196 | .map_err(|e| format!("Error getting task: {e}"))?; |
| 197 | |
| 198 | let original_task = match original_task { |
| 199 | Some(task) => task, |
| 200 | None => return Err(format!("Task with ID '{task_id}' not found")), |
| 201 | }; |
| 202 | |
| 203 | // Validate that the task has been executed (not Queued) |
| 204 | if original_task.status == TaskStatus::Queued { |
| 205 | return Err("Cannot retry a task that hasn't been executed yet".to_string()); |
| 206 | } |
| 207 | |
| 208 | // Use TaskBuilder to create the new task, leveraging from_existing |
| 209 | let mut builder = TaskBuilder::from_existing(&original_task); |
| 210 | |
| 211 | builder = builder.edit(edit_instructions); |
| 212 | |
| 213 | // Apply optional overrides |
| 214 | if let Some(name) = overrides.name { |
| 215 | builder = builder.name(name); |
| 216 | } |
| 217 | if let Some(agent) = overrides.agent { |
| 218 | builder = builder.agent(Some(agent)); |
| 219 | } |
| 220 | if let Some(stack) = overrides.stack { |
| 221 | builder = builder.stack(Some(stack)); |
| 222 | } |
| 223 | if let Some(project) = overrides.project { |
| 224 | builder = builder.project(Some(project)); |
| 225 | } |
| 226 | if let Some(parent_id) = overrides.parent_id { |
| 227 | builder = builder.parent_id(Some(parent_id)); |
| 228 | } |
| 229 | if let Some(dind) = overrides.dind { |
| 230 | builder = builder.dind(Some(dind)); |
| 231 | } |
| 232 | if let Some(privileged) = overrides.privileged { |
| 233 | builder = builder.privileged(Some(privileged)); |
| 234 | } |
| 235 | if let Some(sudo) = overrides.sudo { |
| 236 | builder = builder.sudo(Some(sudo)); |
| 237 | } |
| 238 | if !overrides.devices.is_empty() { |
| 239 | builder = builder.devices(overrides.devices); |
| 240 | } |
| 241 | if let Some(source) = overrides.repo_copy_source { |