Trait crony::Job

source ·
pub trait Job: Send + Sync {
    // Required methods
    fn schedule(&self) -> Schedule;
    fn handle(&self);

    // Provided methods
    fn is_active(&self) -> bool { ... }
    fn allow_parallel_runs(&self) -> bool { ... }
    fn should_run(&self) -> bool { ... }
    fn now(&self) -> DateTime<Utc> { ... }
}

Required Methods§

source

fn schedule(&self) -> Schedule

Define the run schedule for your job

source

fn handle(&self)

This is where your jobs magic happens, define the action that will happen once the cron start running your job

If this method panics, your entire job will panic and that may or may not make the whole runner panic. Handle your errors properly and don’t let it panic.

Provided Methods§

source

fn is_active(&self) -> bool

Default implementation of is_active method will make this job always active

source

fn allow_parallel_runs(&self) -> bool

In case your job takes longer to finish and it’s scheduled to start again (while its still running), default behaviour will skip the next run while one instance is already running. (if your OS has enough threads, and is spawning a thread for next job)

To override this behaviour and enable it to run in parallel with other instances of self, return true on this instance.

source

fn should_run(&self) -> bool

Decide wheather or not to start running your job

source

fn now(&self) -> DateTime<Utc>

Simple output that will return current time so you don’t have to do so in your job if you wish to display the time of the run.

Examples found in repository?
examples/basic.rs (line 11)
10
11
12
    fn handle(&self) {
        println!("Hello, I am a cron job running at: {}", self.now());
    }

Implementors§