Skip to content

Background tasks and async

Trak uses Celery for background jobs and Django Channels for async/websocket support.

Celery

Celery is configured in trak/trak/main/celery.py and settings in trak/trak/main/settings/base.py. Redis is the default broker and result backend (REDIS_URL).

Running workers

Docker (recommended):

make start

This starts the celery service from compose.yml.

Native (outside Docker):

uv run celery -A trak worker -l INFO --pool=solo

The solo pool is recommended for development. Use a production-appropriate pool (e.g. prefork or gevent) in production.

Scheduled tasks (Celery Beat)

Scheduled tasks are defined in SCHEDULED_TASKS in settings and synced into the database with:

python manage.py bootstrap_celery_tasks --remove-stale

In Docker, the celery service runs the worker with --beat enabled.

Channels and websockets

Trak is ASGI-enabled with Channels:

  • ASGI app: trak/trak/main/asgi.py
  • Websocket URLs: trak/trak/main/channels_urls.py
  • Redis channel layer configured in settings

Helpers for websocket URLs live in trak/trak/apps/web/meta.py and the {% websocket_url %} template tag. Set USE_HTTPS_IN_ABSOLUTE_URLS=True in production to generate wss:// URLs.