Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery / Django - How to programatically see workers' states

I just installed Celery and I want to create a simple status page that shows the current number of workers and their status.

Is this possible? From web searches the best I found was celery.current_app.control.inspect()

But as far as I can see, it doesn't mention anything about workers. (I'm using Kombu with SQS for the backend if that matters)

like image 506
Greg Avatar asked Mar 28 '16 14:03

Greg


1 Answers

In the documentation of celery workers it is explained the output of the inspect commands.

By default using celery.current_app.control.inspect() returns an "inspector object" that allows you to ask for the state of all the running workers. For example if you execute this code with two running workers named 'adder' and 'sleeper':

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

the call to i.registered() could return something like:

    {
      '[email protected]': ['tasks.add'],
      '[email protected]': ['tasks.sleeptask'],
    }

In conclusion, the "inspector" methods registered, active, scheduled, etc. return a dictionary with the results classified by the workers chosen when celery.current_app.control.inspect() was called (if no workers are passed as arguments, all workers are implicitly selected).

like image 151
Marco A. Avatar answered Nov 12 '22 08:11

Marco A.