Saturday, February 5, 2022

[SOLVED] Django Crontab : How to stop parallel execution

Issue

I have few cronjobs running with the help of django-crontab. Let us take one cronjob as an example, suppose this job A is scheduled to run every two minutes.

However, while the job is running and if it is not finished in two minutes, I do not want another instance of this job to execute.

Exploring few resources, I came across this article, but I am not sure where to fit this in.

https://bencane.com/2015/09/22/preventing-duplicate-cron-job-executions/

Did someone already came across this issue? How did you fix it?


Solution

According to the readme, you should be able to set:

CRONTAB_LOCK_JOBS = True

in your Django settings. That will prevent a new job instance from starting if a previous one is still running.



Answered By - Will Keeling
Answer Checked By - David Marino (WPSolving Volunteer)