celery - 更改内置 celery 任务的超时(即 celery.backend_cleanup)

标签 celery celerybeat

我们使用 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.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

关于celery - 更改内置 celery 任务的超时(即 celery.backend_cleanup),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53402864/

相关文章:

celery 节拍未启动 EOFError ('Ran out of input' )

python - Django、Django Dynamic Sc​​raper、Djcelery 和 Scrapyd - 不在生产中发送任务

redis - 安装 Celery/Redis 以在另一台服务器上运行任务的正确方法是什么?

python - Django channel 与 celery 有何不同?

django - 我应该如何在 celery 中实现任务集的回调

python - Celery 任务完成后未释放 Redis 连接

python - 多台机器上的 Celery 任务

linux - 如何检测失败并自动重启 celery worker

python - Django Celery Beat 与数据库调度程序未运行任务

django - 使用 Flask 动态安排 Celery Beat 任务