django-tasks-local-db
A Django Tasks backend that combines in-process thread pool execution with database persistence. Tasks run in your web process without a separate worker, while results are durably stored in the database.
This project is a remix of django-tasks-local and django-tasks-db. It builds directly on django-tasks-db's DatabaseBackend and DBTaskResult model, and adds the in-process executor approach from django-tasks-local.
How it works
enqueue()writes a task row to the database (django-tasks-db'sDBTaskResult)- A background watcher thread in each process polls for due tasks and runs them on an in-process thread pool, sending a heartbeat while they run
- On completion, the DB row is updated with the result or error
- A
RUNNINGtask whose heartbeat has gone silent (e.g. the process died) is recovered and re-run by any live process
Tasks are claimed the same way django-tasks-db's db_worker claims them (SELECT ... FOR UPDATE SKIP LOCKED where available, an exclusive transaction on SQLite), so any database django-tasks-db supports works.
Installation
pip install django-tasks-local-db
Configuration
INSTALLED_APPS = [
# ...
"django_tasks_db",
"django_tasks_local_db",
]
TASKS = {
"default": {
"BACKEND": "django_tasks_local_db.LocalDBBackend",
"OPTIONS": {
"MAX_WORKERS": 4, # thread pool size (default 10)
"POLL_INTERVAL": 1.0, # seconds between watcher ticks (default 1.0)
"HEARTBEAT_TIMEOUT": 30, # seconds of silence before a RUNNING task is recovered (default 30)
},
}
}
Then run migrations:
python manage.py migrate
Task results live in django-tasks-db's DBTaskResult table and show up in the admin under Tasks Database Backend, with the heartbeat column and a "Re-enqueue as a new task" action added by this package.
Running on Cloud Run
Tasks run on background threads inside your web process, and by default Cloud Run only allocates CPU to an instance while it is handling a request. Between requests the whole process is throttled to near zero, which stalls both the tasks themselves and the watcher thread that sends their heartbeats. A task enqueued at the end of a request will crawl or freeze until the next request arrives, and if the freeze outlasts HEARTBEAT_TIMEOUT, another instance will treat the task as orphaned and run it a second time.
Turn throttling off with CPU always allocated:
gcloud run services update SERVICE --no-cpu-throttling
(or CPU allocation: CPU is always allocated in the console). This is a separate setting from scaling: an instance with CPU always allocated can still be scaled to zero when idle, at which point it is shut down normally and any in-flight tasks are recovered by heartbeat. If you also want tasks to keep running with no request traffic at all, set --min-instances=1 so there is always a live process to run the watcher.
Upgrading from 0.3.x
0.3.x carried its own copy of the DBTaskResult model. Add "django_tasks_db" to INSTALLED_APPS and run migrate: migration 0005 copies every row from the old django_tasks_local_db_dbtaskresult table into django-tasks-db's table (queued and in-flight tasks included) and then drops the old table. Code that imported DBTaskResult from django_tasks_local_db.models should import it from django_tasks_db.models instead.
Metadata
Release files for django-tasks-local-db 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_tasks_local_db-0.4.0.tar.gz | 29.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_tasks_local_db-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.8 kB
Release files / django_tasks_local_db-0.4.0.tar.gz
| Download URL | django_tasks_local_db-0.4.0.tar.gz |
|---|---|
| Size | 29.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c34dc8da3c411fa349ae66cf37882de6a75bffa5ac46cbe9c9e629109a8757a
|
|
BLAKE2b-256 checksum How to use checksums |
af9cc8cf6805f31b3cbc4e93dc77df47eb422c703dbf044d2e6ffa6f83c47a02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency logRelease files / django_tasks_local_db-0.4.0-py3-none-any.whl
| Download URL | django_tasks_local_db-0.4.0-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81a7ee5dc691c3de76f93226cd67a6135dee008946223ee0a1eda2ec44e471f7
|
|
BLAKE2b-256 checksum How to use checksums |
6383b41a95520de79f22138925da59e111c15c43cadc95ed3af5c29eafba3325
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.
Transparency log