Async worker for django-tasks-db with OpenTelemetry instrumentation
Project description
django-tasks-db-async
Async worker for django-tasks-db with OpenTelemetry instrumentation.
Table of Contents
Installation
pip install django-tasks-db-async
Configuration
Add both django_tasks_db and django_tasks_db_async to INSTALLED_APPS, then configure the TASKS setting to use django_tasks_db.DatabaseBackend:
INSTALLED_APPS = [
...
"django_tasks_db",
"django_tasks_db_async",
]
TASKS = {
"default": {
"BACKEND": "django_tasks_db.DatabaseBackend",
"QUEUES": ["default"],
},
}
Run the database migrations to create the task result table:
python manage.py migrate
Running the worker
Start the worker with the db_async_worker management command:
python manage.py db_async_worker
Options
| Option | Default | Description |
|---|---|---|
--queue-name |
default |
Queue(s) to process. Separate multiple with a comma. Use * to process all queues. |
--interval |
1 |
Seconds to wait when the queue is empty before polling again. |
--concurrency |
10 |
Number of concurrent worker coroutines. |
--batch |
False |
Process all outstanding tasks and exit. |
--max-tasks |
unlimited | Maximum number of tasks each worker will execute before stopping. |
--backend |
default |
Backend alias to operate on (as configured in TASKS). |
--worker-id |
auto | Worker identifier, must be unique across the pool. |
[!NOTE] Each worker coroutine holds one database connection for the duration of its polling loop. A
--concurrencyof 10 (the default) can therefore open up to 10 simultaneous connections. Make sure your database connection pool (orCONN_MAX_AGE) is sized accordingly, and consider lowering--concurrencyif your database has a low connection limit.
Examples
Process tasks from all queues with 4 concurrent workers:
python manage.py db_async_worker --queue-name='*' --concurrency=4
Process tasks from specific queues:
python manage.py db_async_worker --queue-name=default,emails,notifications
Run in batch mode — process outstanding tasks and exit (useful for cron jobs):
python manage.py db_async_worker --batch
Signals
The worker dispatches the standard task_started and task_finished Django signals around each task execution, compatible with both django.tasks (Django 6.0+) and the standalone django-tasks package.
OpenTelemetry
The worker records a span for each task execution using the OpenTelemetry messaging semantic conventions. No additional configuration is required — the worker picks up whatever TracerProvider is active in the process.
Each span includes the following attributes:
| Attribute | Value |
|---|---|
messaging.system |
django_tasks_db |
messaging.operation.type |
process |
messaging.destination.name |
queue name |
messaging.message.id |
task result UUID |
messaging.client.id |
worker ID |
messaging.operation.name |
fully qualified task function name |
Failed tasks set the span status to ERROR and record the exception as a span event.
License
django-tasks-db-async is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_tasks_db_async-0.0.1.tar.gz.
File metadata
- Download URL: django_tasks_db_async-0.0.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ad3f7e874f72dfd97c4e45c2523fe3c8eaece72280e732bbfc9cc84b78bd3dd
|
|
| MD5 |
be7ab7ed75b2a0108be7fe7e35717536
|
|
| BLAKE2b-256 |
16590156182df1f0c350c0a855d2c957a9f71128f29ff04f1b2c5840062ad873
|
Provenance
The following attestation bundles were made for django_tasks_db_async-0.0.1.tar.gz:
Publisher:
release.yml on olist/django-tasks-db-async
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_tasks_db_async-0.0.1.tar.gz -
Subject digest:
0ad3f7e874f72dfd97c4e45c2523fe3c8eaece72280e732bbfc9cc84b78bd3dd - Sigstore transparency entry: 1414248497
- Sigstore integration time:
-
Permalink:
olist/django-tasks-db-async@7093dad4cdf39e4d64337c4ffaf6867ba3ed5d46 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/olist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7093dad4cdf39e4d64337c4ffaf6867ba3ed5d46 -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_tasks_db_async-0.0.1-py3-none-any.whl.
File metadata
- Download URL: django_tasks_db_async-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcbc52a8a8f3bd426e8ad06d6d12cdc717054cb44d92c6285fc431293c31e67d
|
|
| MD5 |
541d77b1547f881a449ee7023a772520
|
|
| BLAKE2b-256 |
1a9abbd64626a1abe6f8a84f197c526c7e62fada53d6c76170f0d7e4113fe52d
|
Provenance
The following attestation bundles were made for django_tasks_db_async-0.0.1-py3-none-any.whl:
Publisher:
release.yml on olist/django-tasks-db-async
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_tasks_db_async-0.0.1-py3-none-any.whl -
Subject digest:
bcbc52a8a8f3bd426e8ad06d6d12cdc717054cb44d92c6285fc431293c31e67d - Sigstore transparency entry: 1414248584
- Sigstore integration time:
-
Permalink:
olist/django-tasks-db-async@7093dad4cdf39e4d64337c4ffaf6867ba3ed5d46 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/olist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7093dad4cdf39e4d64337c4ffaf6867ba3ed5d46 -
Trigger Event:
release
-
Statement type: