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.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Scheduler
impl !UnwindSafe for Scheduler
impl Freeze for Scheduler
impl Send for Scheduler
impl Sync for Scheduler
impl Unpin for Scheduler
impl UnsafeUnpin for Scheduler
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more