pub struct Job(_);
Expand description

A schedulable Job

Implementations§

Create a new cron job.

let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| {
            println!("{:?} Hi I ran", chrono::Utc::now());
        });
sched.add(job)
tokio::spawn(sched.start());

Create a new async cron job.

let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| Box::pin( async move {
            println!("{:?} Hi I ran", chrono::Utc::now());
        }));
sched.add(job)
tokio::spawn(sched.start());

Create a new cron job.

let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new_cron_job("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| {
            println!("{:?} Hi I ran", chrono::Utc::now());
        });
sched.add(job)
tokio::spawn(sched.start());

Create a new async cron job.

let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| Box::pin( async move {
            println!("{:?} Hi I ran", chrono::Utc::now());
        }));
sched.add(job)
tokio::spawn(sched.start());

Create a new one shot job.

This is checked if it is running only after 500ms in 500ms intervals.

let mut sched = JobScheduler::new();
let job = Job::new_one_shot(Duration::from_secs(18), |_uuid, _l| {
           println!("{:?} I'm only run once", chrono::Utc::now());
       }
sched.add(job)
tokio::spawn(sched.start());

Create a new async one shot job.

This is checked if it is running only after 500ms in 500ms intervals.

let mut sched = JobScheduler::new();
let job = Job::new_one_shot(Duration::from_secs(18), |_uuid, _l| Box::pin(async move {
           println!("{:?} I'm only run once", chrono::Utc::now());
       }));
sched.add(job)
tokio::spawn(sched.start());

Create a new one shot job that runs at an instant

// Run after 20 seconds
let mut sched = JobScheduler::new();
let instant = std::time::Instant::now().checked_add(std::time::Duration::from_secs(20));
let job = Job::new_one_shot_at_instant(instant, |_uuid, _lock| println!("I run once after 20 seconds") );
sched.add(job)
tokio::spawn(sched.start());

Create a new async one shot job that runs at an instant

// Run after 20 seconds
let mut sched = JobScheduler::new();
let instant = std::time::Instant::now().checked_add(std::time::Duration::from_secs(20));
let job = Job::new_one_shot_at_instant(instant, |_uuid, _lock| Box::pin(async move {println!("I run once after 20 seconds")}) );
sched.add(job)
tokio::spawn(sched.start());

Create a new repeated job.

This is checked if it is running only after 500ms in 500ms intervals.

let mut sched = JobScheduler::new();
let job = Job::new_repeated(Duration::from_secs(8), |_uuid, _lock| {
    println!("{:?} I'm repeated every 8 seconds", chrono::Utc::now());
}
sched.add(job)
tokio::spawn(sched.start());

Create a new async repeated job.

This is checked if it is running only after 500ms in 500ms intervals.

let mut sched = JobScheduler::new();
let job = Job::new_repeated(Duration::from_secs(8), |_uuid, _lock| Box::pin(async move {
    println!("{:?} I'm repeated every 8 seconds", chrono::Utc::now());
}));
sched.add(job)
tokio::spawn(sched.start());

The tick method returns a true if there was an invocation needed after it was last called This method will also change the last tick on itself

Get the GUID for the job

Add a notification to run on a list of state notifications

Run something when the task is started. Returns a UUID as handle for this notification. This UUID needs to be used when you want to remove the notification handle using on_start_notification_remove.

Remove a notification optionally for a certain type of states

Remove the notification when the task was started. Uses the same UUID that was returned by on_start_notification_add

Run something when the task is stopped. Returns a UUID as handle for this notification. This UUID needs to be used when you want to remove the notification handle using on_stop_notification_remove.

Remove the notification when the task was stopped. Uses the same UUID that was returned by on_done_notification_add

Run something when the task was removed. Returns a UUID as handle for this notification. This UUID needs to be used when you want to remove the notification handle using on_removed_notification_remove.

Remove the notification when the task was removed. Uses the same UUID that was returned by on_removed_notification_add

Run something when the task was removed. Returns a UUID as handle for this notification. This UUID needs to be used when you want to remove the notification handle using on_removed_notification_remove.

Remove the notification when the task was removed. Uses the same UUID that was returned by on_removed_notification_add

Override the job’s data for use in data storage

Set whether this job has been stopped

Get the job data

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more