pub struct CronScheduler {
scheduler: JobScheduler,
storage: Arc<Storage>,
executor: Arc<WorkflowExecutor>,
job_map: Arc<RwLock<HashMap<Uuid, String>>>,
}Expand description
Cron scheduler responsible for managing all scheduled jobs
Features:
- Supports standard cron expressions
- Supports timezone configuration
- Automatically triggers workflow execution
- Persists job mapping relationships
Fields§
§scheduler: JobSchedulertokio-cron-scheduler instance
storage: Arc<Storage>Storage layer used to fetch workflows
executor: Arc<WorkflowExecutor>Workflow executor
job_map: Arc<RwLock<HashMap<Uuid, String>>>job_uuid -> trigger_id mapping table (used for job removal)
Implementations§
Source§impl CronScheduler
impl CronScheduler
Sourcepub async fn new(
storage: Arc<Storage>,
executor: Arc<WorkflowExecutor>,
) -> Result<Self>
pub async fn new( storage: Arc<Storage>, executor: Arc<WorkflowExecutor>, ) -> Result<Self>
Create a new Cron scheduler
Sourcepub async fn add_schedule(
&self,
trigger: &ActiveTrigger,
cron_expr: String,
timezone: Option<String>,
payload: Option<Value>,
) -> Result<()>
pub async fn add_schedule( &self, trigger: &ActiveTrigger, cron_expr: String, timezone: Option<String>, payload: Option<Value>, ) -> Result<()>
Add a scheduled job
§Parameters
trigger: active trigger informationcron_expr: 6-field cron expression (sec min hour day month weekday), e.g. “0 0 0 * * *” for midnight every daytimezone: timezone (e.g. “Asia/Shanghai”), None indicates UTCpayload: payload passed to the workflow when triggered
Sourcepub async fn remove_schedule(&self, trigger_id: &str) -> Result<bool>
pub async fn remove_schedule(&self, trigger_id: &str) -> Result<bool>
Remove a scheduled job
Returns Ok(true) when a job was found and removed, Ok(false) when no job existed, and Err if the underlying scheduler operation failed.
Sourcepub async fn active_job_count(&self) -> usize
pub async fn active_job_count(&self) -> usize
Get the number of active jobs
Auto Trait Implementations§
impl Freeze for CronScheduler
impl !RefUnwindSafe for CronScheduler
impl Send for CronScheduler
impl Sync for CronScheduler
impl Unpin for CronScheduler
impl !UnwindSafe for CronScheduler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more