pub struct Scheduler { /* private fields */ }Expand description
A @Scheduled-style background task runner.
Register tasks with .every(), .after(), or .cron(), then call
.start() to spawn one dedicated background thread per task.
Implementations§
Source§impl Scheduler
impl Scheduler
pub fn new() -> Self
Sourcepub fn every(
self,
interval: Duration,
task: impl Fn() + Send + Sync + 'static,
) -> Self
pub fn every( self, interval: Duration, task: impl Fn() + Send + Sync + 'static, ) -> Self
Run task every interval, measured from the start of the previous run.
If the task takes longer than interval, the next run starts immediately.
Sourcepub fn after(
self,
delay: Duration,
task: impl Fn() + Send + Sync + 'static,
) -> Self
pub fn after( self, delay: Duration, task: impl Fn() + Send + Sync + 'static, ) -> Self
Run task with delay between the end of one run and the start of the next.
Sourcepub fn cron(
self,
expr: &str,
task: impl Fn() + Send + Sync + 'static,
) -> Result<Self, String>
pub fn cron( self, expr: &str, task: impl Fn() + Send + Sync + 'static, ) -> Result<Self, String>
Run task according to a 6-field cron expression.
Format: "second minute hour day-of-month month day-of-week" (UTC).
Each field supports *, an exact value, */step, an N-M range, and
comma-separated combinations, e.g. "0,30 * * * * *" fires at seconds 0 and 30.
Day-of-week: 0 = Sunday, 6 = Saturday.
Sourcepub fn initial_delay(self, delay: Duration) -> Self
pub fn initial_delay(self, delay: Duration) -> Self
Add an initial delay before the first run of the most recently registered task.