A backport of Django's built-in Tasks framework, `django-tasks` provides a robust way to run asynchronous background tasks within Django applications. As of version 0.12.0, it focuses on mirroring the upstream `django.tasks` package, with backends like DB and RQ now available as separate packages. It maintains an active release cadence, frequently updating to support new Django and Python versions.
pip install django-tasksVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a task using the `@task` decorator and enqueue it for asynchronous execution using `.delay()`. It includes a minimal Django configuration for testing, assuming the `django-tasks-db` backend is used and installed.
Install the new packages (e.g., `pip install django-tasks-db django-tasks-rq`) and update your `TASKS_BACKEND` setting in `settings.py` to point to the new backend paths (e.g., `'tasks_db.backends.DatabaseBackend'` or `'tasks_rq.backends.RQBackend'`).
Tasks should be enqueued directly using `.delay()`. If deferred execution within a transaction is required, you will need to implement custom transaction management logic or use a different mechanism.
Update any code referencing `TaskResult.status == 'NEW'` to `TaskResult.status == 'READY'`. Access exceptions and tracebacks via the `task_result.errors` list (e.g., `task_result.errors[0].exception_class`, `task_result.errors[0].traceback`).
Update any code referencing `TaskResult.status == 'completed'` to `TaskResult.status == 'succeeded'`.