This example shows a Celery task queue that uses:
- Redis as the message broker
- CUBRID as the SQLAlchemy business database
- CUBRID (via Celery SQLAlchemy backend) for task result storage
Celery requires Redis (or RabbitMQ). CUBRID is used for business data, not as Celery's broker.
app.py- Celery app configurationdatabase.py- SQLAlchemy engine/session setup for CUBRIDmodels.py- ORM models withcookbook_table prefixestasks/data_tasks.py- business data tasks (aggregate_sales,generate_report,cleanup_old_records)tasks/email_tasks.py- email simulation tasks (send_notification,batch_email)run_tasks.py- submit tasks and inspect results
- Python 3.10+
- Redis running on
localhost:6379 - CUBRID running on
localhost:33000with databasetestdb
Database URL used by this example:
cubrid+pycubrid://dba@localhost:33000/testdb
Broker URL used by this example:
redis://localhost:6379/0
Use this snippet in any existing docker-compose.yml:
services:
redis:
image: redis:7-alpine
container_name: celery-redis
ports:
- "6379:6379"Start Redis:
docker compose up -d redispython -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtcelery -A app:app worker --loglevel=infoIn another shell:
python run_tasks.pyThis submits:
- a task chain:
aggregate_sales -> generate_report - email tasks (
send_notification,batch_email) - cleanup task (
cleanup_old_records)
Run synchronously without broker/worker:
python run_tasks.py --standaloneStandalone mode uses Celery .apply() so you can test task logic with only CUBRID running.
- No Celery Beat (periodic scheduler) is used in this cookbook example.
send_notificationincludes retry logic withbind=Trueandmax_retries=3.- CUBRID has no native BOOLEAN type, so model status flags use string/integer-friendly columns.