Skip to content

Django 6 Tasks Framework support #957

Open

Description

@jrobichaud

Django 6 includes a new tasks framework.

https://docs.djangoproject.com/en/dev/topics/tasks/

It would be nice if django-structlog could work with this new system.

To be discussed.

Activity

  1. jrobichaud commented on Dec 21, 2025

    @jrobichaud
    OwnerAuthor

    There are undocumented signals (task_enqueued, task_started and task_finished):

    https://github.com/django/django/blob/e49e14fd9032feb7a8cf254658ac4e74a4ffb712/django/tasks/signals.py#L13-L15

    I made this diagram to show how it needs to work.

    (It is similar to django_structlog celery's implementation.)

    sequenceDiagram
        autonumber
        participant app as django
        participant broker as Task Broker
        participant django_structlog_app as django_structlog<br>(in App's Process)
        participant shared_storage as Shared storage
        participant django_structlog_worker as django_structlog<br>(in Worker's Process)
        participant worker as Task Worker
        participant task as Task
    
        %% Broker
        app ->>+ broker: Enqueue Task
        broker ->> django_structlog_app: Send "task_enqueued" signal
        django_structlog_app ->> shared_storage: Store context
        broker ->> app: Return task id
    
        %% Worker
        worker ->>+ django_structlog_worker: Send "task_started" signal
        shared_storage ->> django_structlog_worker: Restore context
        django_structlog_worker ->> django_structlog_worker: Log "task_started"
        worker ->>+ task: Start task
        task ->>- worker: Return result
        worker ->> django_structlog_worker: Send "task_finished" signal
        django_structlog_worker ->> django_structlog_worker: Log "task_finished"
    
    Loading

    Django-structlog needs to have shared storage/cache between the app's process (See Store Context (3)) and the worker's process (See Restore context (6)).

    In django_structlog's Celery's implementation the data is stored directly in celery's message.

    Django's implementation uses frozen dataclass which prevents the code to change the task.

    We could use django's cache api.

  2. jrobichaud commented on Dec 21, 2025

    @jrobichaud
    OwnerAuthor

    Anyone knows a third party minimalist django task backend?

    I need to test my implementation of the django task support.

  3. LucidDan commented on Feb 23, 2026

    @LucidDan

    Anyone knows a third party minimalist django task backend?

    I need to test my implementation of the django task support.

    https://github.com/RealOrangeOne/django-tasks-db perhaps?

  4. jrobichaud commented on Apr 6, 2026

    @jrobichaud
    OwnerAuthor

    I tested django-tasks-db and i faced this issue: RealOrangeOne/django-tasks-db#27 where their signals are not propagated to the django task signals.

    That will be a problem with any worker based on django-tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions