llm_incident_manager/scheduler/
error.rs1use crate::error::AppError;
4
5pub type SchedulerResult<T> = std::result::Result<T, SchedulerError>;
7
8#[derive(Debug, thiserror::Error)]
10pub enum SchedulerError {
11 #[error("Failed to start scheduler: {0}")]
13 StartupFailed(String),
14
15 #[error("Failed to shutdown scheduler: {0}")]
17 ShutdownFailed(String),
18
19 #[error("Failed to create job: {0}")]
21 JobCreationFailed(String),
22
23 #[error("Job not found: {0}")]
25 JobNotFound(String),
26
27 #[error("Job execution failed: {0}")]
29 JobExecutionFailed(String),
30
31 #[error("Invalid cron expression: {0}")]
33 InvalidCronExpression(String),
34
35 #[error("Configuration error: {0}")]
37 ConfigurationError(String),
38
39 #[error("Internal scheduler error: {0}")]
41 InternalError(String),
42
43 #[error("Job already exists: {0}")]
45 JobAlreadyExists(String),
46}
47
48impl From<SchedulerError> for AppError {
49 fn from(err: SchedulerError) -> Self {
50 match err {
51 SchedulerError::JobNotFound(msg) => AppError::NotFound(msg),
52 SchedulerError::InvalidCronExpression(msg) | SchedulerError::ConfigurationError(msg) => {
53 AppError::Configuration(msg)
54 }
55 _ => AppError::Internal(err.to_string()),
56 }
57 }
58}
59
60impl From<tokio_cron_scheduler::JobSchedulerError> for SchedulerError {
61 fn from(err: tokio_cron_scheduler::JobSchedulerError) -> Self {
62 SchedulerError::InternalError(format!("tokio-cron-scheduler error: {}", err))
63 }
64}