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