
Django & Celery
Celery setup, tasks, periodic tasks, task routing, retry strategies, monitoring, beat scheduler
1What is the main role of Celery in a Django application?
What is the main role of Celery in a Django application?
回答
Celery is a distributed asynchronous task queue that allows executing long-running or resource-intensive operations in the background, without blocking HTTP requests. This improves user experience by making the application more responsive, particularly for sending emails, image processing, or intensive computations.
2Which Celery component is responsible for storing pending task messages?
Which Celery component is responsible for storing pending task messages?
回答
The message broker (like Redis or RabbitMQ) is the central component that stores task messages pending execution. It acts as an intermediary between the task producer (Django) and the Celery workers that consume and execute these tasks.
3How to define a basic Celery task in a Django application?
How to define a basic Celery task in a Django application?
回答
A Celery task is defined by using the @shared_task or @app.task decorator on a Python function. The @shared_task decorator is preferred as it allows reusing the task across different applications without depending on a specific Celery instance.
What is the difference between task.delay() and task.apply_async()?
Which file is typically created at the root of the Django project to configure Celery?
+19 面接問題