| 177 | |
| 178 | impl AsyncJob for TestJob { |
| 179 | async fn execute(self) -> Result<JobResult, JobError> { |
| 180 | sleep(Duration::from_millis(self.duration_ms)).await; |
| 181 | |
| 182 | if self.should_fail { |
| 183 | Err(JobError::from(format!( |
| 184 | "Job {} failed as requested", |
| 185 | self.id |
| 186 | ))) |
| 187 | } else { |
| 188 | Ok(JobResult { |
| 189 | job_id: self.id.clone(), |
| 190 | success: true, |
| 191 | message: Some(format!( |
| 192 | "Job {} completed after {}ms", |
| 193 | self.id, self.duration_ms |
| 194 | )), |
| 195 | }) |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | fn job_id(&self) -> String { |
| 200 | self.id.clone() |