如何不开始相同的任务并等到 celery beat 完成

How not to start same task and wait until it is finished with celery beat

我已经安排了每 3 小时用芹菜拍打 运行 的任务:

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

有时需要超过 3 小时才能完成任务,我想确保 celery 不会安排并 运行 在旧实例仍在 运行ning 时再次执行任务。

有没有办法只使用 celery 或 celerybeat 设置来做到这一点?

很遗憾,您必须 implement a locking strategy yourself

阅读文档的这一部分以了解更多详细信息:

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).

来源:

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