【问题标题】:Change timeout for builtin celery tasks (i.e. celery.backend_cleanup)更改内置 celery 任务的超时时间(即 celery.backend_cleanup)
【发布时间】:2018-11-20 22:58:18
【问题描述】:

我们正在使用 Celery 4.2.1 和 Redis,并为我们的任务设置了全局软超时和硬超时。我们所有的自定义任务都旨在保持在限制范围内,但每天内置任务 backend_cleanup 任务最终都会因超时而被强制终止。

我宁愿不必为了适应内置的 Celery 任务而提高我们的全局超时。有没有办法直接设置这些内置任务的超时时间?

我找不到任何关于此的文档,甚至找不到遇到相同问题的人。

相关来源来自celery/app/builtins.py

@connect_on_app_finalize
def add_backend_cleanup_task(app):
    """Task used to clean up expired results.

    If the configured backend requires periodic cleanup this task is also
    automatically configured to run every day at 4am (requires
    :program:`celery beat` to be running).
    """
    @app.task(name='celery.backend_cleanup', shared=False, lazy=False)
    def backend_cleanup():
        app.backend.cleanup()
    return backend_cleanup

【问题讨论】:

    标签: celery celerybeat


    【解决方案1】:

    您可以直接在 celery.py 中设置后端清理计划。

    app.conf.beat_schedule = {
        'backend_cleanup': {
            'task': 'celery.backend_cleanup',
            'schedule': 600, # 10 minutes
        },
    }
    

    然后运行beat celery进程:

    celery -A YOUR_APP_NAME beat -l info --detach
    

    【讨论】:

      猜你喜欢
      • 2016-05-03
      • 2020-05-24
      • 2013-12-16
      • 2023-03-09
      • 2016-07-30
      • 2017-05-09
      • 1970-01-01
      • 2019-02-26
      • 2016-09-28
      相关资源
      最近更新 更多