Struct crony::Runner

source ·
pub struct Runner { /* private fields */ }
Expand description

Runner that will hold all the jobs and will start up the execution and eventually will stop it.

Implementations§

source§

impl Runner

source

pub fn new() -> Self

Create new runner

Examples found in repository?
examples/basic.rs (line 16)
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let mut runner = Runner::new();

    println!("Adding ExampleJob to the Runner");
    runner = runner.add(Box::new(ExampleJob));

    println!("Starting the Runner for 20 seconds");
    runner = runner.run();
    thread::sleep(Duration::from_millis(20 * 1000));

    println!("Stopping the Runner");
    runner.stop();
}
source

pub fn add(self, job: Box<dyn Job>) -> Self

Add jobs into the runner

panics if you try to push a job onto already started runner

Examples found in repository?
examples/basic.rs (line 19)
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let mut runner = Runner::new();

    println!("Adding ExampleJob to the Runner");
    runner = runner.add(Box::new(ExampleJob));

    println!("Starting the Runner for 20 seconds");
    runner = runner.run();
    thread::sleep(Duration::from_millis(20 * 1000));

    println!("Stopping the Runner");
    runner.stop();
}
source

pub fn jobs_to_run(&self) -> usize

Number of jobs ready to start running

source

pub fn run(self) -> Self

Start the loop and job execution

Examples found in repository?
examples/basic.rs (line 22)
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let mut runner = Runner::new();

    println!("Adding ExampleJob to the Runner");
    runner = runner.add(Box::new(ExampleJob));

    println!("Starting the Runner for 20 seconds");
    runner = runner.run();
    thread::sleep(Duration::from_millis(20 * 1000));

    println!("Stopping the Runner");
    runner.stop();
}
source

pub fn stop(self)

Stop the spawned runner

Examples found in repository?
examples/basic.rs (line 26)
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    let mut runner = Runner::new();

    println!("Adding ExampleJob to the Runner");
    runner = runner.add(Box::new(ExampleJob));

    println!("Starting the Runner for 20 seconds");
    runner = runner.run();
    thread::sleep(Duration::from_millis(20 * 1000));

    println!("Stopping the Runner");
    runner.stop();
}
source

pub fn is_running(&self) -> bool

Lets us know if the cron worker is running

source

pub fn is_working(&self) -> bool

Lets us know if the worker is in the process of executing a job currently

Trait Implementations§

source§

impl Default for Runner

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Runner

§

impl Send for Runner

§

impl Sync for Runner

§

impl Unpin for Runner

§

impl !UnwindSafe for Runner

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.