Celery / Django - How to programmatically see the status of workers

I just installed Celery, and I want to create a simple status page showing the current number of employees and their status.

Is it possible? From a web search, the best I found was celery.current_app.control.inspect()

But, as far as I see, he does not say anything about the workers. (I use Kombu with SQS for the backend, if that matters)

+5
source share
1 answer

The celery worker documentation explains the output of inspect commands.

By default, using celery.current_app.control.inspect() , an inspector object is returned that allows you to query the status of all workers. For example, if you are executing this code with two working workers with the names β€œadder” and β€œsleep”:

  i = celery.current_app.control.inspect() i.registered() 

calling i.registered() might return something like:

  { ' adder@example.com ': ['tasks.add'], ' sleeper@example.com ': ['tasks.sleeptask'], } 

In conclusion, the inspector methods are registered , active , scheduled , etc. will return a dictionary with the results classified by workers selected by calling celery.current_app.control.inspect() (if none of the workers are passed as arguments, all employees are implicitly selected).

+7
source

Source: https://habr.com/ru/post/1245912/


All Articles