Check status of Celery worker

谁都会走 提交于 2019-12-05 06:55:37

问题


I have a project that uses Celery. I am periodically running into a scenario where my requests are making it to Celery but the tasks aren't being handed off to the workers, but rather the server is just returning a 500 error.

When I restart Celery it starts working again. I am only guessing that the worker is hanging which makes it so there aren't anymore workers available. If I startup another batch of workers the requests start working again (which supports my theory).

Questions:

  1. I understand celery by default logs to stderr. I am not seeing any errors, so I am hoping there is another celery log somewhere. Where would that be?
  2. Is there any way to lookup the status of workers? Are they available? Are they hung?
  3. Could it be anything else?

回答1:


you can see active workers using flower API or by directly querying celery using below manner:

from celery import Celery
celery = Celery('vwadaptor',
                broker='redis://workerdb:6379/0',backend='redis://workerdb:6379/0')
celery.control.inspect().active()

Shows you the active workers and their currently executing jobs.




回答2:


You can install flower:

pip install flower

It has an API that can be used to ask for the status of the workers and tasks running on them.




回答3:


To get a quick status of your workers you can run this command:

celery -A project inspect stats

it will output a JSON array with lot statistics about your workers.

See docs for more details.




回答4:


I understand celery by default logs to stderr. I am not seeing any errors, so I am hoping there is another celery log somewhere. Where would that be?

Celery logger will write to the file you specified with --logfile=/path/to/file.log. If you did not specify it, it will go, as you say, to stderr.

Is there any way to lookup the status of workers? Are they available? Are they hung?

Yes, it is all covered by the Monitoring and Management Guide of the Celery documentation.

celery -A yourproject.app inspect status will give the status of your workers. celery -A yourproject.app inspect active will give you list of tasks currently running, etc.

Could it be anything else?

Celery does not return any 500 errors. What are you referring to? Celery flower perhaps? - Celery is not a web server... So it is perfectly possible that your Celery cluster works fine, but you are confused with Celery Flower, or some other web server, being down.



来源:https://stackoverflow.com/questions/36582225/check-status-of-celery-worker

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