Skip to main content

Async worker for django-tasks-db with OpenTelemetry instrumentation

Project description

django-tasks-db-async

PyPI - Version PyPI - Python Version

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 --concurrency of 10 (the default) can therefore open up to 10 simultaneous connections. Make sure your database connection pool (or CONN_MAX_AGE) is sized accordingly, and consider lowering --concurrency if 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_tasks_db_async-0.0.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_tasks_db_async-0.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

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

Hashes for django_tasks_db_async-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0ad3f7e874f72dfd97c4e45c2523fe3c8eaece72280e732bbfc9cc84b78bd3dd
MD5 be7ab7ed75b2a0108be7fe7e35717536
BLAKE2b-256 16590156182df1f0c350c0a855d2c957a9f71128f29ff04f1b2c5840062ad873

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_tasks_db_async-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_tasks_db_async-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcbc52a8a8f3bd426e8ad06d6d12cdc717054cb44d92c6285fc431293c31e67d
MD5 541d77b1547f881a449ee7023a772520
BLAKE2b-256 1a9abbd64626a1abe6f8a84f197c526c7e62fada53d6c76170f0d7e4113fe52d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page