如何在Heroku上运行时解决celeryd的退出超时问题(错误R12)?

Hen*_*ger 13 heroku celery django-celery celeryd

我在Heroku dyno上运行celeryd.当我关闭它并且它先前已处理(甚至已完成)至少一个任务时,它没有正确关闭,我从Heroku收到错误R12(退出超时).

这是我从我的Procfile(通过Django和django-celery)运行celeryd的方式:

celeryd: python manage.py celeryd -E --loglevel=INFO
Run Code Online (Sandbox Code Playgroud)

这是我正在做的触发它:

> heroku ps:scale web=0 celeryd=0 --app myapp
Run Code Online (Sandbox Code Playgroud)

这是我得到的日志输出:

2012-09-07T12:56:31+00:00 heroku[celeryd.1]: State changed from up to down
2012-09-07T12:56:31+00:00 heroku[api]: Scale to celeryd=0, web=1 by mail@mydomain.com
2012-09-07T12:56:32+00:00 heroku[web.1]: State changed from up to down
2012-09-07T12:56:32+00:00 heroku[api]: Scale to web=0 by mail@mydomain.com
2012-09-07T12:56:34+00:00 heroku[celeryd.1]: Stopping all processes with SIGTERM
2012-09-07T12:56:35+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2012-09-07T12:56:37+00:00 heroku[web.1]: Process exited with status 143
2012-09-07T12:56:43+00:00 heroku[celeryd.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
2012-09-07T12:56:43+00:00 heroku[celeryd.1]: Stopping remaining processes with SIGKILL
2012-09-07T12:56:45+00:00 heroku[celeryd.1]: Process exited with status 137
Run Code Online (Sandbox Code Playgroud)

最初,我在芹菜2.5.5上体验过这一点.现在我升级到3.0.9,我仍然遇到同样的问题.

据我所知,我的任务已全部完成.通过在芹菜dyno上运行单个任务可以可靠地重现此错误,从而给它足够的时间来完成然后关闭dyno.

我不知道还有什么要检查.知道如何解决这个问题吗?什么可以阻止芹菜在任务完成后响应Heroku的SIGTERM?

Nei*_*ton -1

在我看来,芹菜没有捕获SIGTERM信号并对其做出反应,而是等待信号SIGKILL到达。

此拉取请求可能会帮助您: https://github.com/cybertoast/celery/commit/e9a007b982b0f9268174ae94b351a9275eaef4a3