Retrieve list of tasks in a queue in Celery
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Celery is an asynchronous task queue/job queue that is based on distributed message passing. It is used for executing tasks concurrently across multiple worker processes while managing task distribution, execution status, and retries. In many scenarios, it becomes crucial to retrieve the current state of tasks in a queue for monitoring and debugging purposes. This article dives into how we can retrieve a list of tasks within a Celery queue using various approaches.
Technical Overview
Celery operates with a broker — commonly RabbitMQ or Redis — which holds the tasks until a worker processes them. Workers, defined in separate processes or machines, execute these tasks. Each task in Celery is an instance of the Task class which can hold states and results in a backend of your choice — from RPC to database storage solutions.
Task States
Celery tasks can have several states:
- `PENDING`: Task is waiting to be executed.
- `STARTED`: Task has been started.
- `SUCCESS`: Task has been successfully executed.
- `FAILURE`: Task execution failed.
- `RETRY`: Task is being retried after encountering an error.
- Other states such as `REVOKED` and `RECEIVED` depending on configuration.
When tasks are put into a queue, they usually start with a `PENDING` state, transition to `STARTED`, and finally `SUCCESS` or `FAILURE`. These states are essential for monitoring the progress or bottlenecks within processing pipelines.
Connection to Broker
To retrieve tasks queued in Celery, you generally connect directly to the message broker used by Celery. This connection can either be programmatically handled or manually if required for one-off debugging purposes.
Retrieving the Task List
Imposing a Solution Using Celery Events
Celery provides a powerful tool known as Celery Events, which is part of the `celery.events` module. Celery Events work by listening to the messages produced by the task’s state changes and worker’s life-cycle events. The `celery events` command, part of celery's command-line tool, can provide real-time insights and task tracking.
Example using the command:
Related reading
- Retrieve multiple messages from SQS
- Retrieve queue length with Celery (RabbitMQ, Django)
- Retrieve Timestamp based data from Kafka
- Retrieving number of unacknowledged messages in RabbitMQ queue from Java/ Spring
- Retrieving Dictionary Value Best Practices
- Retrieving the top 100 numbers from one hundred million of numbers
- Retry policy in CompletionService
- Retrying a failed async/promise function?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.