pub struct CronScheduler { /* private fields */ }Expand description
Cron scheduler that integrates with the virtual clock
Implementations§
Source§impl CronScheduler
impl CronScheduler
Sourcepub fn new(clock: Arc<VirtualClock>) -> Self
pub fn new(clock: Arc<VirtualClock>) -> Self
Create a new cron scheduler
Sourcepub fn new_with_global_clock() -> Self
pub fn new_with_global_clock() -> Self
Create a new cron scheduler using the global clock
This will use the global virtual clock registry if available, or create a new clock if none is registered.
Sourcepub async fn add_job(
&self,
job: CronJob,
action: CronJobAction,
) -> Result<(), String>
pub async fn add_job( &self, job: CronJob, action: CronJobAction, ) -> Result<(), String>
Add a cron job
Sourcepub async fn remove_job(&self, job_id: &str) -> bool
pub async fn remove_job(&self, job_id: &str) -> bool
Remove a cron job
Sourcepub async fn set_job_enabled(
&self,
job_id: &str,
enabled: bool,
) -> Result<(), String>
pub async fn set_job_enabled( &self, job_id: &str, enabled: bool, ) -> Result<(), String>
Enable or disable a cron job
Sourcepub async fn check_and_execute(&self) -> Result<usize, String>
pub async fn check_and_execute(&self) -> Result<usize, String>
Check for jobs that should execute now and execute them
This should be called periodically (e.g., every second) to check if any jobs are due for execution.
Sourcepub fn clock(&self) -> Arc<VirtualClock>
pub fn clock(&self) -> Arc<VirtualClock>
Get the virtual clock
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
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>
Converts
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>
Converts
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