Struct Runner

Source
pub struct Runner {
    pub jobs: Vec<Box<dyn Job>>,
    pub thread: Option<JoinHandle<()>>,
    pub running: bool,
    pub tx: Option<UnboundedSender<Result<(), ()>>>,
    pub working: Arc<AtomicBool>,
}
Expand description

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

Fields§

§jobs: Vec<Box<dyn Job>>

the current jobs

§thread: Option<JoinHandle<()>>

the task that is running the handle

§running: bool

is the task running or not

§tx: Option<UnboundedSender<Result<(), ()>>>

channel sending message

§working: Arc<AtomicBool>

tracker to determine crons working

Implementations§

Source§

impl Runner

Source

pub fn new() -> Self

Create new runner

Examples found in repository?
examples/example.rs (line 21)
20async fn run() {
21    let mut runner = Runner::new();
22    println!("Adding ExampleJob to the Runner");
23    runner = runner.add(Box::new(ExampleJob));
24    println!("Starting the Runner for 20 seconds");
25    runner = runner.run().await;
26    tokio::time::sleep(Duration::from_millis(20 * 1000)).await;
27    println!("Stopping the Runner");
28    runner.stop().await;
29}
Source

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

Add jobs into the runner

Does nothing if already running.

Examples found in repository?
examples/example.rs (line 23)
20async fn run() {
21    let mut runner = Runner::new();
22    println!("Adding ExampleJob to the Runner");
23    runner = runner.add(Box::new(ExampleJob));
24    println!("Starting the Runner for 20 seconds");
25    runner = runner.run().await;
26    tokio::time::sleep(Duration::from_millis(20 * 1000)).await;
27    println!("Stopping the Runner");
28    runner.stop().await;
29}
Source

pub fn jobs_to_run(&self) -> usize

Number of jobs ready to start running

Source

pub async fn run(self) -> Self

Start the loop and job execution

Examples found in repository?
examples/example.rs (line 25)
20async fn run() {
21    let mut runner = Runner::new();
22    println!("Adding ExampleJob to the Runner");
23    runner = runner.add(Box::new(ExampleJob));
24    println!("Starting the Runner for 20 seconds");
25    runner = runner.run().await;
26    tokio::time::sleep(Duration::from_millis(20 * 1000)).await;
27    println!("Stopping the Runner");
28    runner.stop().await;
29}
Source

pub async fn stop(&mut self)

Stop the spawned runner

Examples found in repository?
examples/example.rs (line 28)
20async fn run() {
21    let mut runner = Runner::new();
22    println!("Adding ExampleJob to the Runner");
23    runner = runner.add(Box::new(ExampleJob));
24    println!("Starting the Runner for 20 seconds");
25    runner = runner.run().await;
26    tokio::time::sleep(Duration::from_millis(20 * 1000)).await;
27    println!("Stopping the Runner");
28    runner.stop().await;
29}
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 Freeze for Runner

§

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 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.