Type Definition jact::Job [−][src]
Expand description
A schedulable Job
Trait 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_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 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 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 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());