9

I have scheduled task with celery beat to run every 3 hours:

'sync_stuff': {
    'task': 'celery_tasks.sync_stuff',
    'schedule': crontab(hour='*/3')
}

Sometimes it takes longer than 3 hours to finish the task and I want to ensure that celery does not schedule and run the task again while the old instance is still running.

Is there a way to do that just with celery or celerybeat settings?

Ivan Lebediev
  • 507
  • 4
  • 15
  • Possible duplicate of [Prevent Celery Beat from running the same task](https://stackoverflow.com/questions/31730964/prevent-celery-beat-from-running-the-same-task) – DejanLekic Jul 01 '19 at 14:57
  • There have been numerous threads about this on StackOverflow. This is a duplicate. – DejanLekic Jul 01 '19 at 14:57

1 Answers1

7

Unfortunately, you have to implement a locking strategy yourself.

Read this part of the doc for additional details:

Like with cron, the tasks may overlap if the first task doesn’t complete before the next. If that’s a concern you should use a locking strategy to ensure only one instance can run at a time (see for example Ensuring a task is only executed one at a time).

Sources:

http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#entries http://docs.celeryproject.org/en/latest/tutorials/task-cookbook.html#cookbook-task-serial

sashaboulouds
  • 1,566
  • 11
  • 16