django-celery works in development, fails in wsgi production: How to debug?

帅比萌擦擦* 提交于 2020-01-04 14:09:13

问题


I'm using the django celery task queue, and it works fine in development, but not at all in wsgi production. Even more frustrating, it used to work in production, but I somehow broke it.

"sudo rabbitmqctl status" tells me that the rabbitmq server is working. Everything also seems peachy in django: objects are created, and routed to the task manager without problems. But then their status just stays as "queued" indefinitely. The way I've written my code, they should switch to "error" or "ready," as soon as anything gets returned from the celery task. So I assume there's something wrong with the queue.

Two related questions:

  • Any ideas what the problem might be?
  • How do I debug celery? Outside of the manage.py celeryd command, I'm not sure how to peer into its inner workings. Are there log files or something I can use?

Thanks!

PS - I've seen this question, but he seems to want to run celery from manage.py, not wsgi.


回答1:


After much searching, the most complete answer I found for this question is here. These directions flesh out the skimpy official directions for daemonizing celeryd. I'll copy the gist here, but you should follow the link, because Michael has explained some parts in more detail.

The main idea is that you need scripts in three places:

  1. /etc/init.d/celeryd
  2. /etc/default/celeryd
  3. myApp/settings.py

Settings.py appears to be the same as in development mode. So if that's already set up, there are four steps to shifting to production:

  1. Download the daemon script since it's not included in the installation: https://github.com/celery/celery/tree/3.0/extra/generic-init.d/
  2. Put it in /etc/init.d/celeryd
  3. Make a file in /etc/default/celeryd, and put the variables here into it: http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#example-django-configuration
  4. Start the script

This solved my problem.




回答2:


I think the reason you are not getting any response from celery, is because celeryd server might not be running. You could find out about it by doing ps -ef |grep celeryd. In order to figure out what is the error while trying to run celeryd, you might want to do the following.

In your settings.py file you could give the path to the celery log file CELERYD_LOG_FILE = <Path to the log file> and while running celeryd server you could specify the level manage.py celeryd -l DEBUG.



来源:https://stackoverflow.com/questions/8404325/django-celery-works-in-development-fails-in-wsgi-production-how-to-debug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!