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)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
pub fn main() {
  let mut scheduler = Scheduler::new(4);

  scheduler.schedule_job("Every 1 minutes", "* * * * *", || {
    println!("Executes every minute: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 2 minutes", &every_n_minutes(2), || {
    println!("Executes two minutes: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 3 minutes", &every_n_minutes(3), || {
    println!("Executes three minutes: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 5 minutes", &every_n_minutes(5), || {
    println!("Executes five minutes: {}", now().rfc3339());
  });

  println!("Running scheduler example: {}", now().rfc3339());
  scheduler.run();
}
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)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
pub fn main() {
  let mut scheduler = Scheduler::new(4);

  scheduler.schedule_job("Every 1 minutes", "* * * * *", || {
    println!("Executes every minute: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 2 minutes", &every_n_minutes(2), || {
    println!("Executes two minutes: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 3 minutes", &every_n_minutes(3), || {
    println!("Executes three minutes: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 5 minutes", &every_n_minutes(5), || {
    println!("Executes five minutes: {}", now().rfc3339());
  });

  println!("Running scheduler example: {}", now().rfc3339());
  scheduler.run();
}
Source

pub fn run(&mut self) -> !

Run the jobs.

Examples found in repository?
examples/timers.rs (line 30)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
pub fn main() {
  let mut scheduler = Scheduler::new(4);

  scheduler.schedule_job("Every 1 minutes", "* * * * *", || {
    println!("Executes every minute: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 2 minutes", &every_n_minutes(2), || {
    println!("Executes two minutes: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 3 minutes", &every_n_minutes(3), || {
    println!("Executes three minutes: {}", now().rfc3339());
  });

  scheduler.schedule_job("Every 5 minutes", &every_n_minutes(5), || {
    println!("Executes five minutes: {}", now().rfc3339());
  });

  println!("Running scheduler example: {}", now().rfc3339());
  scheduler.run();
}

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.