Celery Overview
Celery is a distributed task queue used for async processing in Maybern. It handles expensive calculations, background jobs, and workflow orchestration.What is Celery?
Celery allows you to run tasks asynchronously outside the request-response cycle. This is essential for:- Expensive calculations (waterfalls, XIRR)
- PDF generation
- Email sending
- Event processing
- Background data updates
Core Concepts
Native Celery Primitives
- Task
- Chord
- Chain
A single function to be executed asynchronously:
Why Maybern Wraps Celery
We’ve built custom wrappers around Celery for several reasons:Clarity
Celery’s API can be confusing. Our wrappers provide a cleaner, more intuitive interface.
Performance
Celery puts all task parameters on the queue, which doesn’t scale. We store data in Redis instead.
Flexibility
Abstracting Celery makes it easier to switch task queue libraries if needed.
Observability
Our wrappers add consistent logging, error handling, and monitoring.
Task Definition
Define tasks using the@simple_celery_task decorator:
Task Parameters
Every task receives:| Parameter | Description |
|---|---|
ctx | Request context with customer, user, feature flags |
celery_workflow_id | Unique ID for tracking the workflow |
task_data | Typed dataclass with task-specific data |
Queue Configuration
Tasks are assigned to queues based on their type:| Queue | Use For |
|---|---|
DEFAULT | General tasks, low priority |
CORE_COMPUTATION | Financial calculations |
CORE_COMPUTATION_HIGH_PRIORITY | User-initiated calculations |
NOTICES | PDF/notice generation |
Running Celery Locally
1
Start Redis
2
Start Celery workers
Celery workers run in a separate process from the Django server. Make sure both are running for async tasks to work.
Error Handling
Tasks have built-in error handling:Debugging Tasks
View task logs
View task logs
Celery logs appear in the terminal running
just run-celery.Check Redis
Check Redis
Inspect task data in Redis:
Use remote debugger
Use remote debugger