systemprompt_traits/
scheduler.rs1use async_trait::async_trait;
4use std::sync::Arc;
5
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum SchedulerError {
9 #[error("Job not found: {0}")]
10 JobNotFound(String),
11
12 #[error("Scheduler unavailable: {0}")]
13 Unavailable(String),
14
15 #[error("Job execution failed: {0}")]
16 ExecutionFailed(String),
17
18 #[error("Internal error: {0}")]
19 Internal(String),
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23#[non_exhaustive]
24pub enum JobStatus {
25 Pending,
26 Running,
27 Success,
28 Failed,
29 Disabled,
30}
31
32#[derive(Debug, Clone)]
33pub struct JobInfo {
34 pub name: String,
35 pub status: JobStatus,
36 pub last_run: Option<chrono::DateTime<chrono::Utc>>,
37 pub next_run: Option<chrono::DateTime<chrono::Utc>>,
38 pub run_count: i64,
39 pub last_error: Option<String>,
40}
41
42#[async_trait]
43pub trait JobTrigger: Send + Sync {
44 async fn trigger_job(&self, job_name: &str) -> Result<(), SchedulerError>;
45
46 async fn get_job_status(&self, job_name: &str) -> Result<JobInfo, SchedulerError>;
47
48 async fn list_jobs(&self) -> Result<Vec<JobInfo>, SchedulerError>;
49
50 async fn is_running(&self) -> bool;
51}
52
53#[async_trait]
54pub trait SchedulerLifecycle: Send + Sync {
55 async fn start(&self) -> Result<(), SchedulerError>;
56
57 async fn stop(&self) -> Result<(), SchedulerError>;
58
59 async fn health_check(&self) -> Result<bool, SchedulerError>;
60}
61
62pub type DynJobTrigger = Arc<dyn JobTrigger>;
63
64pub type DynSchedulerLifecycle = Arc<dyn SchedulerLifecycle>;