【问题标题】:How not to start same task and wait until it is finished with celery beat如何不开始相同的任务并等到它用 celery beat 完成
【发布时间】:2019-11-12 02:09:46
【问题描述】:

我已经安排了 celery beat 任务,每 3 小时运行一次:

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

有时完成任务需要超过 3 个小时,我想确保 celery 在旧实例仍在运行时不会再次调度和运行任务。

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

【问题讨论】:

标签: python celery celerybeat


【解决方案1】:

很遗憾,你必须implement a locking strategy yourself。

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

与 cron 一样,如果第一个任务在下一个任务之前没有完成,任务可能会重叠。如果这是一个问题,您应该使用锁定策略来确保一次只能运行一个实例(参见示例确保一次只执行一个任务)。

来源:

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

【讨论】:

    猜你喜欢
    • 2015-10-24
    • 2015-10-22
    • 2023-01-10
    • 2018-09-17
    • 2020-02-27
    • 2021-06-13
    • 2020-02-26
    • 2020-03-15
    • 2015-07-07
    相关资源
    最近更新 更多