Struct tokio_cron_scheduler::JobScheduler [−][src]
The JobScheduler contains and executes the scheduled jobs.
Implementations
impl JobsSchedulerLocked
[src]
pub fn new() -> JobsSchedulerLocked
[src]
Create a new JobSchedulerLocked
.
pub fn add(&mut self, job: JobLocked) -> Result<(), Box<dyn Error>>
[src]
Add a job to the JobScheduler
use tokio_cron_scheduler::{Job, JobScheduler, JobToRun}; let mut sched = JobScheduler::new(); sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || { println!("I get executed every 10 seconds!"); }));
pub fn remove(&mut self, to_be_removed: &Uuid) -> Result<(), Box<dyn Error>>
[src]
Remove a job from the JobScheduler
use tokio_cron_scheduler::{Job, JobScheduler, JobToRun}; let mut sched = JobScheduler::new(); let job_id = sched.add(Job::new("1/10 * * * * *".parse().unwrap(), || { println!("I get executed every 10 seconds!"); })); sched.remove(job_id);
pub fn tick(&mut self) -> Result<(), Box<dyn Error>>
[src]
The tick
method increments time for the JobScheduler and executes
any pending jobs. It is recommended to sleep for at least 500
milliseconds between invocations of this method.
This is kept public if you’re running this yourself. It is better to
call the start
method if you want all of this automated for you.
loop { sched.tick(); std::thread::sleep(Duration::from_millis(500)); }
pub fn start(&self) -> JoinHandle<()>
[src]
The start
spawns a Tokio task where it loops. Every 500ms it
runs the tick method to increment any
any pending jobs.
if let Err(e) = sched.start().await { eprintln!("Error on scheduler {:?}", e); }
pub fn time_till_next_job(&self) -> Result<Duration, Box<dyn Error>>
[src]
The time_till_next_job
method returns the duration till the next job
is supposed to run. This can be used to sleep until then without waking
up at a fixed interval.AsMut
loop { sched.tick(); std::thread::sleep(sched.time_till_next_job()); }
Trait Implementations
impl Clone for JobsSchedulerLocked
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for JobsSchedulerLocked
[src]
Auto Trait Implementations
impl RefUnwindSafe for JobsSchedulerLocked
impl Send for JobsSchedulerLocked
impl Sync for JobsSchedulerLocked
impl Unpin for JobsSchedulerLocked
impl UnwindSafe for JobsSchedulerLocked
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,