Struct Scheduler

Source
pub struct Scheduler { /* private fields */ }
Expand description

Scheduler manages scheduling of new jobs and maintains a threadpool upon which the scheduled jobs run.

Implementations§

Source§

impl<'a> Scheduler

Source

pub fn new(pool_size: usize) -> Scheduler

Create a new scheduler.

Examples found in repository?
examples/timers.rs (line 11)
10pub fn main() {
11  let mut scheduler = Scheduler::new(4);
12
13  scheduler.schedule_job("Every 1 minutes", "* * * * *", || {
14    println!("Executes every minute: {}", now().rfc3339());
15  });
16
17  scheduler.schedule_job("Every 2 minutes", &every_n_minutes(2), || {
18    println!("Executes two minutes: {}", now().rfc3339());
19  });
20
21  scheduler.schedule_job("Every 3 minutes", &every_n_minutes(3), || {
22    println!("Executes three minutes: {}", now().rfc3339());
23  });
24
25  scheduler.schedule_job("Every 5 minutes", &every_n_minutes(5), || {
26    println!("Executes five minutes: {}", now().rfc3339());
27  });
28
29  println!("Running scheduler example: {}", now().rfc3339());
30  scheduler.run();
31}
Source

pub fn schedule_job<F>(&mut self, name: &str, schedule: &str, function: F)
where F: FnMut() + Send + Sync + 'static,

Schedule a new job for execution.

Examples found in repository?
examples/timers.rs (lines 13-15)
10pub fn main() {
11  let mut scheduler = Scheduler::new(4);
12
13  scheduler.schedule_job("Every 1 minutes", "* * * * *", || {
14    println!("Executes every minute: {}", now().rfc3339());
15  });
16
17  scheduler.schedule_job("Every 2 minutes", &every_n_minutes(2), || {
18    println!("Executes two minutes: {}", now().rfc3339());
19  });
20
21  scheduler.schedule_job("Every 3 minutes", &every_n_minutes(3), || {
22    println!("Executes three minutes: {}", now().rfc3339());
23  });
24
25  scheduler.schedule_job("Every 5 minutes", &every_n_minutes(5), || {
26    println!("Executes five minutes: {}", now().rfc3339());
27  });
28
29  println!("Running scheduler example: {}", now().rfc3339());
30  scheduler.run();
31}
Source

pub fn run(&mut self) -> !

Run the jobs.

Examples found in repository?
examples/timers.rs (line 30)
10pub fn main() {
11  let mut scheduler = Scheduler::new(4);
12
13  scheduler.schedule_job("Every 1 minutes", "* * * * *", || {
14    println!("Executes every minute: {}", now().rfc3339());
15  });
16
17  scheduler.schedule_job("Every 2 minutes", &every_n_minutes(2), || {
18    println!("Executes two minutes: {}", now().rfc3339());
19  });
20
21  scheduler.schedule_job("Every 3 minutes", &every_n_minutes(3), || {
22    println!("Executes three minutes: {}", now().rfc3339());
23  });
24
25  scheduler.schedule_job("Every 5 minutes", &every_n_minutes(5), || {
26    println!("Executes five minutes: {}", now().rfc3339());
27  });
28
29  println!("Running scheduler example: {}", now().rfc3339());
30  scheduler.run();
31}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.