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() -> Scheduler
Sourcepub fn every(
self,
interval: Duration,
task: impl Fn() + Send + Sync + 'static,
) -> Scheduler
pub fn every( self, interval: Duration, task: impl Fn() + Send + Sync + 'static, ) -> Scheduler
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,
) -> Scheduler
pub fn after( self, delay: Duration, task: impl Fn() + Send + Sync + 'static, ) -> Scheduler
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<Scheduler, String>
pub fn cron( self, expr: &str, task: impl Fn() + Send + Sync + 'static, ) -> Result<Scheduler, 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) -> Scheduler
pub fn initial_delay(self, delay: Duration) -> Scheduler
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.