Tivix / django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-)
www.tivix.com
MIT License
900 stars 193 forks source link

Job costing more time than cron interval? #140

Closed laixintao closed 2 years ago

laixintao commented 6 years ago

What if I have a cron job run every minute, but the job cost 3min to finish?

From the code I think all of the jobs will be delayed, aka, the job actually behave like running every 3min.

Can we add H:M to lock name? Like change this to f{jobname}-{hour}:{minute}? But if so, we have to query the db first, I am not sure if there are any race conditions.

msopko81 commented 6 years ago

You can turn on ALLOW_PARALLEL_RUNS to allow for the job to run every minute. But this is a global option for all jobs.

Unless you are referring to having parallel runs for a single job and the other jobs not allowed to run in parallel. This case is not possible at the moment.

laixintao commented 6 years ago

Thanks for reply.

The case is, I have 4 runcrons runs parallelly, and I have a cronjob run for every minute, but one job cost 3 minutes.

Let's say, at 00:01, one job started, and, at 00:02, the job hasn't finished, so all other 3 process was blocked. The next run could be at 00:04 ( when the 00:01 job finished).


If I turn ALLOW_PArALLEL_RUNS on, then at 00:01, the job will be run 4 times. (because I have 4 runcron process)

JedrzejMaluszczak commented 2 years ago

You are right " all of the jobs will be delayed, aka, the job actually behave like running every 3min." It behaves the same way for run_at_times. If the first task doesn't complete, the second task will be delayed and will run right after the first.