Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery Get List Of Registered Tasks

Tags:

python

celery

Is there a way to get a list of registered tasks?

I tried:

celery_app.tasks.keys() 

Which only returns built in Celery tasks like celery.chord, celery.chain etc.

like image 411
Richard Knop Avatar asked Sep 26 '14 11:09

Richard Knop


People also ask

How do I check my celery queue?

Just to spell things out, the DATABASE_NUMBER used by default is 0 , and the QUEUE_NAME is celery , so redis-cli -n 0 llen celery will return the number of queued messages.

What is the difference between celery and RabbitMQ?

From my understanding, Celery is a distributed task queue, which means the only thing that it should do is dispatching tasks/jobs to others servers and get the result back. RabbitMQ is a message queue, and nothing more. However, a worker could just listen to the MQ and execute the task when a message is received.


Video Answer


2 Answers

For the newer versions of celery(4.0 or above), we can get registered tasks as follows.

from celery import current_app  tasks = current_app.tasks.keys() 

For older versions of celery, celery < 4, we can get registered tasks as follows.

from celery.task.control import  inspect i = inspect() i.registered_tasks() 

This will give a dictionary of all workers & related registered tasks.

from itertools import chain set(chain.from_iterable( i.registered_tasks().values() )) 

In case if you have multiple workers running same tasks or if you just need a set of all registered tasks, it does the job.

Alternate Way:

From terminal you can get a dump of registered tasks by using this command

celery inspect registered 

To inspect tasks related to a specific app, you can pass app name

celery -A app_name inspect registered 
like image 93
Pandikunta Anand Reddy Avatar answered Oct 02 '22 02:10

Pandikunta Anand Reddy


With the newer versions of celery ( 4.0 and above ), the following seems to be the right way:

 from celery import current_app   current_app.loader.import_default_modules()   tasks = list(sorted(name for name in current_app.tasks                             if not name.startswith('celery.')))  return tasks 
like image 40
Navid Khan Avatar answered Oct 02 '22 01:10

Navid Khan