pub struct Scheduler { /* private fields */ }Expand description
A declarative scheduler for recurring asynchronous jobs.
Each registered task has exactly one serial execution loop. A slow run
therefore skips already-missed cron instants instead of creating unbounded
overlapping tasks. Handler futures execute in isolated Tokio tasks so their
panics can be converted into SchedulerError values.
Implementations§
Source§impl Scheduler
impl Scheduler
Sourcepub fn with_task_timeout(self, timeout: Duration) -> Scheduler
pub fn with_task_timeout(self, timeout: Duration) -> Scheduler
Sets the maximum duration of one handler execution.
Sourcepub fn with_failure_policy(self, policy: SchedulerFailurePolicy) -> Scheduler
pub fn with_failure_policy(self, policy: SchedulerFailurePolicy) -> Scheduler
Selects whether a failing task continues at its next tick or stops.
Sourcepub fn task<F, Fut>(
self,
cron_expr: &str,
handler: F,
) -> Result<Scheduler, SchedulerError>
pub fn task<F, Fut>( self, cron_expr: &str, handler: F, ) -> Result<Scheduler, SchedulerError>
Registers a recurring task using a standard five-field cron expression.
§Errors
Returns SchedulerError::InvalidCron when the expression cannot be
parsed.
Sourcepub fn start(self) -> Result<SchedulerHandle, SchedulerError>
pub fn start(self) -> Result<SchedulerHandle, SchedulerError>
Starts every registered task and returns its lifecycle handle.
Dropping the handle aborts all scheduler loops and their current handler
futures. Prefer SchedulerHandle::shutdown for graceful cancellation.
§Errors
Returns SchedulerError::RuntimeUnavailable without spawning anything
when called outside Tokio.
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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