Python & FastAPI•Part 5: ORMs, Databases & Background Workers (56 - 65)
Celery Architecture: Broker & Result Backend:
In Simple Words:
- Broker (RabbitMQ/Redis): Queues task messages.
- Worker: Consumes and executes tasks.
- Result Backend (Redis/DB): Stores task return values and statuses.
python
from celery import Celery
celery_app = Celery(
'tasks',
broker='redis://localhost:6379/0',
backend='redis://localhost:6379/1'
)
@celery_app.task
def generate_pdf_report(user_id: int):
return f"Report for user {user_id} generated."