mvniekerk / tokio-cron-scheduler

Schedule tasks on Tokio using cron-like annotation
Apache License 2.0
497 stars 60 forks source link

Overlapping of Jobs #83

Open abhi3700 opened 1 day ago

abhi3700 commented 1 day ago

Suppose, a job takes longer time than usual & then the next thread opens for the new job. In this situation there could be an overlapping. I want to avoid this to happen.

A situation like this: image

Is there a property available to set in a job such that it disallow overlapping of the 2 jobs?

Expecting a code like this:

let job1 = Job::new_async("1/2 * * * * *", move |_uuid, _lock| {
        Box::pin(async move {
            if let Err(e) = perform_task_1().await {
                error!("Error executing Job 1: {}", e);
            } else {
                info!("Job 1 executed successfully.");
            }
        })
    })
    .unwrap()
    .set_allow_overlap(false);
abhi3700 commented 1 day ago

I think I can protect this by having Mutex for a local data type. And in case of using a DB (with drivers normally having states as Mutex type), I need to maintain a field there that locks when something is running inside a Job & then release lock (& thereby change the state) when done.