taskferry-django 0.2.0__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. taskferry_django-0.3.1/CHANGELOG.md +57 -0
  2. taskferry_django-0.3.1/PKG-INFO +204 -0
  3. taskferry_django-0.3.1/README.md +180 -0
  4. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/pyproject.toml +3 -2
  5. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/__init__.py +3 -1
  6. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/backend.py +24 -16
  7. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/execute.py +37 -3
  8. taskferry_django-0.3.1/src/taskferry_django/results.py +30 -0
  9. taskferry_django-0.2.0/CHANGELOG.md +0 -36
  10. taskferry_django-0.2.0/PKG-INFO +0 -132
  11. taskferry_django-0.2.0/README.md +0 -109
  12. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/.gitignore +0 -0
  13. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/LICENSE +0 -0
  14. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/apps.py +0 -0
  15. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/checks.py +0 -0
  16. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/config.py +0 -0
  17. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/management/__init__.py +0 -0
  18. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/management/commands/__init__.py +0 -0
  19. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/management/commands/taskferry.py +0 -0
  20. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/py.typed +0 -0
  21. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/transaction.py +0 -0
  22. {taskferry_django-0.2.0 → taskferry_django-0.3.1}/src/taskferry_django/views.py +0 -0
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes to `taskferry-django` are documented here.
4
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
+ this project adheres to [Semantic Versioning](https://semver.org/).
6
+
7
+ ## Unreleased
8
+
9
+ ## [0.3.1] — 2026-11-27
10
+
11
+ ### Added
12
+
13
+ - Native Django `TaskContext` propagation for execution-context-capable backends.
14
+ - `TaskferryTaskResult.provider_id`, while keeping `TaskResult.id` as the
15
+ Taskferry execution id.
16
+
17
+ ### Changed
18
+
19
+ - Align `taskferry_django.__version__` with the distribution version `0.3.1`.
20
+
21
+ ## [0.3.0] — 2026-11-26
22
+
23
+ ### Changed
24
+
25
+ - **BREAKING**: Require Django 6.0+, matching the native `django.tasks` imports.
26
+ The package does not target the third-party backport on Django 5.x.
27
+ - Do not advertise `supports_async_task` or `supports_get_result`: the dispatcher
28
+ is synchronous and the bridge does not persist Django-specific `TaskResult`
29
+ records. Calling `get_result()` raises `NotImplementedError`.
30
+
31
+ ## [0.2.0] — 2026-07-26
32
+
33
+ ### Changed
34
+
35
+ - Reduced to a pure bridge. `TaskferryBackend` is a `django.tasks` backend that
36
+ translates to `TaskSpec` and hands it to a Taskferry runtime; the engine is a
37
+ configuration choice, not a Django class.
38
+ - Feature flags and capabilities now come from the *routed* backend rather than
39
+ being hardcoded per class.
40
+
41
+ ### Added
42
+
43
+ - `config_from_settings()` — the only place in the project that reads
44
+ `django.conf.settings`.
45
+ - `submit_on_commit()` / `task_on_commit()`, built on `transaction.on_commit`.
46
+ - System checks that build every configured backend at `manage.py check` time.
47
+ - `manage.py taskferry <subcommand>`, wrapping the same CLI.
48
+ - `taskferry_django.execute:run_task`, the single worker-side dispatcher.
49
+
50
+ ### Removed
51
+
52
+ - Provider integrations are maintained by their dedicated distributions,
53
+ including `taskferry-cloudtasks`, `taskferry-procrastinate`, `taskferry-sqs`,
54
+ `taskferry-servicebus`, and `taskferry-dramatiq`.
55
+ - The Cloud Tasks request handler is available as
56
+ `taskferry_cloudtasks.handle_request` and accepts request bytes.
57
+ - Backend support is described by `taskferry.Capability`.
@@ -0,0 +1,204 @@
1
+ Metadata-Version: 2.5
2
+ Name: taskferry-django
3
+ Version: 0.3.1
4
+ Summary: Django integration for Taskferry — a django.tasks backend, settings, checks and CLI.
5
+ Project-URL: Homepage, https://github.com/xiidigital/taskferry
6
+ Project-URL: Documentation, https://taskferry.dev/django
7
+ Project-URL: Source, https://github.com/xiidigital/taskferry
8
+ Author: Taskferry authors
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: cloud-tasks,django,django-tasks,sqs,taskferry
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: Django
14
+ Classifier: Framework :: Django :: 6.0
15
+ Classifier: Framework :: Django :: 6.1
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: django>=6.0
22
+ Requires-Dist: taskferry<0.3,>=0.2
23
+ Description-Content-Type: text/markdown
24
+
25
+ # taskferry-django
26
+
27
+ Django integration for [Taskferry](https://github.com/xiidigital/taskferry).
28
+
29
+ ```mermaid
30
+ flowchart BT
31
+ DJ["Django"]
32
+ TPD["taskferry-django"]
33
+ TP["taskferry"]
34
+
35
+ DJ --> TPD --> TP
36
+ ```
37
+
38
+ This package supports **Django 6.0+ native `django.tasks`**. Django introduced
39
+ that API in 6.0; this package imports it directly and does not integrate the
40
+ third-party `django-tasks` backport. Taskferry does **not** invent a parallel API. This
41
+ package supplies a backend for the standard `TASKS` setting, so your `@task` code
42
+ never changes while the engine behind it becomes a configuration choice.
43
+
44
+ ```bash
45
+ pip install taskferry-django taskferry-procrastinate
46
+ ```
47
+
48
+ ## Your code never changes
49
+
50
+ ```python
51
+ # myapp/tasks.py
52
+ from django.tasks import task
53
+
54
+
55
+ @task
56
+ def resize_image(image_id: int) -> None: ...
57
+ ```
58
+
59
+ ```python
60
+ # anywhere
61
+ resize_image.enqueue(42)
62
+ ```
63
+
64
+ ## Settings
65
+
66
+ ```python
67
+ TASKS = {"default": {"BACKEND": "taskferry_django.TaskferryBackend"}}
68
+
69
+ TASKFERRY = {
70
+ "backends": {
71
+ "celery": {"factory": "celery", "app": "myproject.celery:app"},
72
+ "gcp": {
73
+ "factory": "cloudtasks",
74
+ "project": "my-project",
75
+ "location": "us-central1",
76
+ "url": "https://example.run.app/_taskferry/execute",
77
+ },
78
+ },
79
+ "routes": [
80
+ {"kind": "task", "queue": "local-workers", "backend": "celery"},
81
+ {"kind": "task", "queue": "serverless", "backend": "gcp"},
82
+ ],
83
+ "defaults": {"task": "celery"},
84
+ }
85
+ ```
86
+
87
+ For Celery, configure broker/result storage on `myproject.celery:app` itself;
88
+ the backend name in Taskferry chooses the Celery execution adapter, while Celery
89
+ chooses its broker and optional result store. Change the queue routes or default
90
+ to move Django tasks between Celery and Cloud Tasks without changing task code.
91
+
92
+ With no `TASKFERRY` setting at all, everything runs locally — a fresh project works
93
+ immediately and is obviously not production.
94
+
95
+ ### Choosing execution and storage
96
+
97
+ Choose an engine through `TASKFERRY.backends` and route queues with the usual
98
+ `routes`/`defaults` configuration. Django's native Tasks API is the enqueue
99
+ interface; it does not include a production queue or durable task store. Provider
100
+ integrations are separate optional distributions:
101
+
102
+ ```bash
103
+ pip install taskferry-django taskferry-celery[celery]
104
+ # If Redis is your chosen Celery broker and/or result backend:
105
+ pip install 'taskferry-celery[redis]'
106
+ # If RabbitMQ is your chosen Celery broker:
107
+ pip install 'taskferry-celery[rabbitmq]'
108
+ # For GCP push delivery:
109
+ pip install taskferry-django 'taskferry-cloudtasks[gcp]'
110
+ ```
111
+
112
+ Celery's broker and result backend are configured on the Celery app, independently
113
+ of Taskferry routing. Redis is optional; Celery can use other supported brokers
114
+ and result stores, or run without result storage. The `rabbitmq` extra is an
115
+ installation alias; Celery includes its AMQP transport. RabbitMQ can also use
116
+ Celery's transient `rpc://` result backend, or pair with a separate database
117
+ result backend. The Taskferry Celery adapter
118
+ advertises result retrieval only when `app.conf.result_backend` is configured.
119
+ Cloud Tasks is a push queue: it cannot report execution state or persist return
120
+ values, so persist progress and results in application-owned storage if required.
121
+
122
+ Taskferry serializes task names and arguments as JSON; pass identifiers or other
123
+ JSON-safe values, never ORM instances or pickled objects. Cloud Tasks provides
124
+ time-bounded task-name deduplication when an idempotency key is supplied; Celery
125
+ does not, so keyed submissions are rejected there. Cloud Tasks and Celery retry
126
+ through their native engines according to the Taskferry retry policy. Delivery
127
+ can be duplicated: make task handlers idempotent. Celery revoke is best effort
128
+ and does not interrupt a running handler; Cloud Tasks does not expose cancellation.
129
+ Taskferry has no portable progress reporting contract yet. Celery's persisted
130
+ state can show queued/started/terminal state when configured, but richer progress
131
+ belongs in application storage.
132
+
133
+ ### `TaskContext` and provider ids
134
+
135
+ Tasks declared with Django's native `@task(takes_context=True)` receive Django's
136
+ `TaskContext` from the Taskferry dispatcher. `context.task_result.id` is the
137
+ portable Taskferry execution id; the enqueue result exposes the provider's
138
+ separate native id as `result.provider_id` (for example, a Celery task UUID or a
139
+ Cloud Tasks resource name). Reading `provider_id` does not require `get_result()`
140
+ or a provider state lookup.
141
+
142
+ Context tasks are accepted only on backends that supply the portable execution
143
+ id and current attempt: the local thread backend, Celery, and Cloud Tasks. Other
144
+ adapters reject them before enqueueing until they can provide that metadata.
145
+ Celery uses its retry counter; Cloud Tasks uses
146
+ `X-CloudTasks-TaskRetryCount + 1`; the thread backend counts its own retry loop.
147
+ The context result is marked `RUNNING`, has current arguments and the observed
148
+ start time, and reports the current attempt. `enqueued_at` is `None` because the
149
+ dispatcher cannot recover the provider's enqueue timestamp. Prior attempt errors
150
+ and worker history are not persisted by Taskferry; worker ids are included only
151
+ when the engine exposes the current worker id. These fields are not a substitute
152
+ for a durable Django `TaskResult` store, and `get_result()` remains unsupported.
153
+
154
+ ## What else you get
155
+
156
+ **Enqueue after commit.** The classic race — a worker reaching a row before the
157
+ transaction that created it commits — with the classic fix:
158
+
159
+ ```python
160
+ from django.db import transaction
161
+ from taskferry_django import task_on_commit
162
+
163
+
164
+ def create_order(request):
165
+ with transaction.atomic():
166
+ order = Order.objects.create(...)
167
+ task_on_commit("myapp.tasks:process_order", order.id)
168
+ ```
169
+
170
+ **System checks.** `manage.py check` builds every configured backend, because
171
+ "the adapter is installed" and "the adapter works with these options" are
172
+ different questions:
173
+
174
+ ```text
175
+ taskferry.E002 the Taskferry backend 'heavy' cannot be built: CloudRunJobBackend
176
+ needs both 'project' and 'location'
177
+ taskferry.W003 DEBUG is False but these Taskferry backends run in this process and
178
+ lose pending work on restart: fast
179
+ ```
180
+
181
+ **The CLI, with settings loaded.**
182
+
183
+ ```bash
184
+ python manage.py taskferry doctor
185
+ python manage.py taskferry capabilities pg
186
+ ```
187
+
188
+ **Jobs and inline execution**, through the same runtime:
189
+
190
+ ```python
191
+ from taskferry_django import get_runtime
192
+
193
+ get_runtime().jobs.submit("build-cog", image="gdal:latest", profile="heavy")
194
+ ```
195
+
196
+ ## The dependency direction
197
+
198
+ `taskferry` never imports Django. The test suite for the core runs — and CI runs
199
+ it — in an environment where Django is not installed. The same `TASKFERRY` dict
200
+ works verbatim in a FastAPI service, a CLI or a library.
201
+
202
+ ## License
203
+
204
+ Apache-2.0.
@@ -0,0 +1,180 @@
1
+ # taskferry-django
2
+
3
+ Django integration for [Taskferry](https://github.com/xiidigital/taskferry).
4
+
5
+ ```mermaid
6
+ flowchart BT
7
+ DJ["Django"]
8
+ TPD["taskferry-django"]
9
+ TP["taskferry"]
10
+
11
+ DJ --> TPD --> TP
12
+ ```
13
+
14
+ This package supports **Django 6.0+ native `django.tasks`**. Django introduced
15
+ that API in 6.0; this package imports it directly and does not integrate the
16
+ third-party `django-tasks` backport. Taskferry does **not** invent a parallel API. This
17
+ package supplies a backend for the standard `TASKS` setting, so your `@task` code
18
+ never changes while the engine behind it becomes a configuration choice.
19
+
20
+ ```bash
21
+ pip install taskferry-django taskferry-procrastinate
22
+ ```
23
+
24
+ ## Your code never changes
25
+
26
+ ```python
27
+ # myapp/tasks.py
28
+ from django.tasks import task
29
+
30
+
31
+ @task
32
+ def resize_image(image_id: int) -> None: ...
33
+ ```
34
+
35
+ ```python
36
+ # anywhere
37
+ resize_image.enqueue(42)
38
+ ```
39
+
40
+ ## Settings
41
+
42
+ ```python
43
+ TASKS = {"default": {"BACKEND": "taskferry_django.TaskferryBackend"}}
44
+
45
+ TASKFERRY = {
46
+ "backends": {
47
+ "celery": {"factory": "celery", "app": "myproject.celery:app"},
48
+ "gcp": {
49
+ "factory": "cloudtasks",
50
+ "project": "my-project",
51
+ "location": "us-central1",
52
+ "url": "https://example.run.app/_taskferry/execute",
53
+ },
54
+ },
55
+ "routes": [
56
+ {"kind": "task", "queue": "local-workers", "backend": "celery"},
57
+ {"kind": "task", "queue": "serverless", "backend": "gcp"},
58
+ ],
59
+ "defaults": {"task": "celery"},
60
+ }
61
+ ```
62
+
63
+ For Celery, configure broker/result storage on `myproject.celery:app` itself;
64
+ the backend name in Taskferry chooses the Celery execution adapter, while Celery
65
+ chooses its broker and optional result store. Change the queue routes or default
66
+ to move Django tasks between Celery and Cloud Tasks without changing task code.
67
+
68
+ With no `TASKFERRY` setting at all, everything runs locally — a fresh project works
69
+ immediately and is obviously not production.
70
+
71
+ ### Choosing execution and storage
72
+
73
+ Choose an engine through `TASKFERRY.backends` and route queues with the usual
74
+ `routes`/`defaults` configuration. Django's native Tasks API is the enqueue
75
+ interface; it does not include a production queue or durable task store. Provider
76
+ integrations are separate optional distributions:
77
+
78
+ ```bash
79
+ pip install taskferry-django taskferry-celery[celery]
80
+ # If Redis is your chosen Celery broker and/or result backend:
81
+ pip install 'taskferry-celery[redis]'
82
+ # If RabbitMQ is your chosen Celery broker:
83
+ pip install 'taskferry-celery[rabbitmq]'
84
+ # For GCP push delivery:
85
+ pip install taskferry-django 'taskferry-cloudtasks[gcp]'
86
+ ```
87
+
88
+ Celery's broker and result backend are configured on the Celery app, independently
89
+ of Taskferry routing. Redis is optional; Celery can use other supported brokers
90
+ and result stores, or run without result storage. The `rabbitmq` extra is an
91
+ installation alias; Celery includes its AMQP transport. RabbitMQ can also use
92
+ Celery's transient `rpc://` result backend, or pair with a separate database
93
+ result backend. The Taskferry Celery adapter
94
+ advertises result retrieval only when `app.conf.result_backend` is configured.
95
+ Cloud Tasks is a push queue: it cannot report execution state or persist return
96
+ values, so persist progress and results in application-owned storage if required.
97
+
98
+ Taskferry serializes task names and arguments as JSON; pass identifiers or other
99
+ JSON-safe values, never ORM instances or pickled objects. Cloud Tasks provides
100
+ time-bounded task-name deduplication when an idempotency key is supplied; Celery
101
+ does not, so keyed submissions are rejected there. Cloud Tasks and Celery retry
102
+ through their native engines according to the Taskferry retry policy. Delivery
103
+ can be duplicated: make task handlers idempotent. Celery revoke is best effort
104
+ and does not interrupt a running handler; Cloud Tasks does not expose cancellation.
105
+ Taskferry has no portable progress reporting contract yet. Celery's persisted
106
+ state can show queued/started/terminal state when configured, but richer progress
107
+ belongs in application storage.
108
+
109
+ ### `TaskContext` and provider ids
110
+
111
+ Tasks declared with Django's native `@task(takes_context=True)` receive Django's
112
+ `TaskContext` from the Taskferry dispatcher. `context.task_result.id` is the
113
+ portable Taskferry execution id; the enqueue result exposes the provider's
114
+ separate native id as `result.provider_id` (for example, a Celery task UUID or a
115
+ Cloud Tasks resource name). Reading `provider_id` does not require `get_result()`
116
+ or a provider state lookup.
117
+
118
+ Context tasks are accepted only on backends that supply the portable execution
119
+ id and current attempt: the local thread backend, Celery, and Cloud Tasks. Other
120
+ adapters reject them before enqueueing until they can provide that metadata.
121
+ Celery uses its retry counter; Cloud Tasks uses
122
+ `X-CloudTasks-TaskRetryCount + 1`; the thread backend counts its own retry loop.
123
+ The context result is marked `RUNNING`, has current arguments and the observed
124
+ start time, and reports the current attempt. `enqueued_at` is `None` because the
125
+ dispatcher cannot recover the provider's enqueue timestamp. Prior attempt errors
126
+ and worker history are not persisted by Taskferry; worker ids are included only
127
+ when the engine exposes the current worker id. These fields are not a substitute
128
+ for a durable Django `TaskResult` store, and `get_result()` remains unsupported.
129
+
130
+ ## What else you get
131
+
132
+ **Enqueue after commit.** The classic race — a worker reaching a row before the
133
+ transaction that created it commits — with the classic fix:
134
+
135
+ ```python
136
+ from django.db import transaction
137
+ from taskferry_django import task_on_commit
138
+
139
+
140
+ def create_order(request):
141
+ with transaction.atomic():
142
+ order = Order.objects.create(...)
143
+ task_on_commit("myapp.tasks:process_order", order.id)
144
+ ```
145
+
146
+ **System checks.** `manage.py check` builds every configured backend, because
147
+ "the adapter is installed" and "the adapter works with these options" are
148
+ different questions:
149
+
150
+ ```text
151
+ taskferry.E002 the Taskferry backend 'heavy' cannot be built: CloudRunJobBackend
152
+ needs both 'project' and 'location'
153
+ taskferry.W003 DEBUG is False but these Taskferry backends run in this process and
154
+ lose pending work on restart: fast
155
+ ```
156
+
157
+ **The CLI, with settings loaded.**
158
+
159
+ ```bash
160
+ python manage.py taskferry doctor
161
+ python manage.py taskferry capabilities pg
162
+ ```
163
+
164
+ **Jobs and inline execution**, through the same runtime:
165
+
166
+ ```python
167
+ from taskferry_django import get_runtime
168
+
169
+ get_runtime().jobs.submit("build-cog", image="gdal:latest", profile="heavy")
170
+ ```
171
+
172
+ ## The dependency direction
173
+
174
+ `taskferry` never imports Django. The test suite for the core runs — and CI runs
175
+ it — in an environment where Django is not installed. The same `TASKFERRY` dict
176
+ works verbatim in a FastAPI service, a CLI or a library.
177
+
178
+ ## License
179
+
180
+ Apache-2.0.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "taskferry-django"
7
- version = "0.2.0"
7
+ version = "0.3.1"
8
8
  description = "Django integration for Taskferry — a django.tasks backend, settings, checks and CLI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -16,12 +16,13 @@ classifiers = [
16
16
  "Development Status :: 3 - Alpha",
17
17
  "Framework :: Django",
18
18
  "Framework :: Django :: 6.0",
19
+ "Framework :: Django :: 6.1",
19
20
  "Intended Audience :: Developers",
20
21
  "License :: OSI Approved :: Apache Software License",
21
22
  "Programming Language :: Python :: 3 :: Only",
22
23
  "Typing :: Typed",
23
24
  ]
24
- dependencies = ["taskferry>=0.2,<0.3", "django>=5.1"]
25
+ dependencies = ["taskferry>=0.2,<0.3", "django>=6.0"]
25
26
 
26
27
  [project.urls]
27
28
  Homepage = "https://github.com/xiidigital/taskferry"
@@ -64,13 +64,15 @@ from __future__ import annotations
64
64
  from .backend import TaskferryBackend
65
65
  from .config import config_from_settings, get_runtime, reset_runtime
66
66
  from .execute import run_task
67
+ from .results import TaskferryTaskResult
67
68
  from .transaction import submit_on_commit, task_on_commit
68
69
  from .views import make_task_webhook, task_webhook
69
70
 
70
- __version__ = "0.2.0"
71
+ __version__ = "0.3.1"
71
72
 
72
73
  __all__ = [
73
74
  "TaskferryBackend",
75
+ "TaskferryTaskResult",
74
76
  "__version__",
75
77
  "config_from_settings",
76
78
  "get_runtime",
@@ -31,11 +31,12 @@ from typing import Any
31
31
  from django.tasks.backends.base import BaseTaskBackend
32
32
  from django.tasks.base import Task, TaskResult, TaskResultStatus
33
33
 
34
- from taskferry import CapabilitySet, ExecutionState, Taskferry, TaskSpec
35
- from taskferry.errors import TaskferryError
34
+ from taskferry import Capability, CapabilitySet, ExecutionKind, ExecutionState, Taskferry, TaskSpec
35
+ from taskferry.execution import new_execution_id
36
36
 
37
37
  from .config import get_runtime
38
38
  from .execute import DISPATCH_REF
39
+ from .results import TaskferryTaskResult
39
40
 
40
41
  #: Portable state -> the Django Tasks status vocabulary. Django's enum is
41
42
  #: coarser than Taskferry's, so several states collapse; the mapping is written
@@ -75,8 +76,11 @@ class TaskferryBackend(BaseTaskBackend):
75
76
  #: permissively and the real, per-backend answer is enforced at submit time
76
77
  #: by the capability check, which raises rather than silently degrading.
77
78
  supports_defer = True
78
- supports_async_task = True
79
- supports_get_result = True
79
+ # The dispatcher invokes Task.call() synchronously and the portable runtime
80
+ # has no durable Django TaskResult store. Do not advertise features we cannot
81
+ # guarantee across workers or process restarts.
82
+ supports_async_task = False
83
+ supports_get_result = False
80
84
  supports_priority = True
81
85
 
82
86
  def __init__(self, alias: str, params: dict[str, Any]) -> None:
@@ -125,6 +129,9 @@ class TaskferryBackend(BaseTaskBackend):
125
129
  """Translate a Django task into a spec and submit it."""
126
130
  self.validate_task(task)
127
131
  spec = self.build_spec(task, args, kwargs)
132
+ if task.takes_context:
133
+ name = self._pinned or self.runtime.router.resolve(spec)
134
+ self.runtime.capabilities(str(name)).require(Capability.EXECUTION_CONTEXT)
128
135
  handle = self.runtime.submit(spec, backend=self._pinned)
129
136
  return self._task_result(task, args, kwargs, handle.execution)
130
137
 
@@ -148,6 +155,7 @@ class TaskferryBackend(BaseTaskBackend):
148
155
  run_at=task.run_after,
149
156
  name=task.name,
150
157
  labels={"django_task": task.module_path},
158
+ execution_id=(new_execution_id(ExecutionKind.TASK) if task.takes_context else None),
151
159
  )
152
160
 
153
161
  def _task_result(
@@ -156,10 +164,10 @@ class TaskferryBackend(BaseTaskBackend):
156
164
  args: list[Any],
157
165
  kwargs: dict[str, Any],
158
166
  execution: Any,
159
- ) -> TaskResult:
167
+ ) -> TaskferryTaskResult:
160
168
  from django.utils import timezone
161
169
 
162
- return TaskResult(
170
+ return TaskferryTaskResult(
163
171
  task=task,
164
172
  # Django caps result ids at 64 characters; a Taskferry id is well
165
173
  # inside that, which is one reason ids are minted rather than
@@ -175,21 +183,21 @@ class TaskferryBackend(BaseTaskBackend):
175
183
  backend=self.alias,
176
184
  errors=[],
177
185
  worker_ids=[],
186
+ provider_id=execution.external_id,
178
187
  )
179
188
 
180
189
  def get_result(self, result_id: str) -> TaskResult:
181
- """Look up a previously enqueued task.
190
+ """Django result lookup is not backed by durable task metadata here.
182
191
 
183
- Raises:
184
- TaskferryError: when the routed backend cannot report state. Django's
185
- API implies every backend can look a result up; most real queues
186
- cannot, and this says so instead of returning a fabricated one.
192
+ Django Tasks requires a stored ``TaskResult`` including its original Task
193
+ object, arguments, attempts, and errors. The portable execution backends
194
+ do not persist that Django-specific record, so pretending a Taskferry
195
+ execution lookup is equivalent would return incomplete or fabricated data.
187
196
  """
188
- raise TaskferryError(
189
- "get_result() is not supported through the Taskferry bridge: use "
190
- "runtime.get(execution_id) directly, where the backend's capabilities "
191
- "are visible and an unsupported lookup fails honestly"
197
+ raise NotImplementedError(
198
+ f"Taskferry does not persist Django TaskResult records (id={result_id!r}); "
199
+ "use the Taskferry runtime and its configured backend capabilities"
192
200
  )
193
201
 
194
202
 
195
- __all__ = ["TaskferryBackend"]
203
+ __all__ = ["TaskferryBackend", "TaskferryTaskResult"]
@@ -43,10 +43,13 @@ from __future__ import annotations
43
43
  import importlib
44
44
  from typing import Any
45
45
 
46
- from django.tasks.base import Task
46
+ from django.tasks.base import Task, TaskContext, TaskResultStatus
47
47
 
48
48
  from taskferry.core.typing import JSONValue
49
- from taskferry.errors import FunctionResolutionError
49
+ from taskferry.errors import FunctionResolutionError, UnsupportedCapability
50
+ from taskferry.execution_context import current_task_execution
51
+
52
+ from .results import TaskferryTaskResult
50
53
 
51
54
 
52
55
  def resolve_django_task(module_path: str) -> Task:
@@ -92,7 +95,38 @@ def run_task(
92
95
  advertise ``RESULT`` surface it through the handle.
93
96
  """
94
97
  task = resolve_django_task(module_path)
95
- return task.call(*(args or []), **(kwargs or {}))
98
+ call_args = args or []
99
+ call_kwargs = kwargs or {}
100
+ if not task.takes_context:
101
+ return task.call(*call_args, **call_kwargs)
102
+
103
+ current = current_task_execution()
104
+ if current is None or current.execution_id is None or current.attempt is None:
105
+ raise UnsupportedCapability(
106
+ "execution_context",
107
+ provider="the selected Taskferry backend did not supply an execution id and attempt",
108
+ )
109
+
110
+ from django.utils import timezone
111
+
112
+ started_at = current.started_at or timezone.now()
113
+ result = TaskferryTaskResult(
114
+ task=task,
115
+ id=str(current.execution_id),
116
+ status=TaskResultStatus.RUNNING,
117
+ enqueued_at=None,
118
+ started_at=started_at,
119
+ finished_at=None,
120
+ last_attempted_at=started_at,
121
+ args=list(call_args),
122
+ kwargs=dict(call_kwargs),
123
+ backend=task.backend,
124
+ errors=[],
125
+ worker_ids=[] if current.worker_id is None else [current.worker_id],
126
+ provider_id=None,
127
+ _current_attempt=current.attempt,
128
+ )
129
+ return task.call(TaskContext(task_result=result), *call_args, **call_kwargs)
96
130
 
97
131
 
98
132
  DISPATCH_REF = "taskferry_django.execute:run_task"
@@ -0,0 +1,30 @@
1
+ """Django TaskResult extension for Taskferry identity metadata."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+
7
+ from django.tasks.base import TaskResult
8
+
9
+
10
+ @dataclass(frozen=True, slots=True, kw_only=True)
11
+ class TaskferryTaskResult(TaskResult):
12
+ """Django result with portable and provider ids kept distinct.
13
+
14
+ ``id`` remains the Taskferry execution id. ``provider_id`` is the native
15
+ queue/task identifier reported at enqueue time; it does not imply that the
16
+ backend can later retrieve state or results.
17
+ """
18
+
19
+ provider_id: str | None = None
20
+ _current_attempt: int | None = field(default=None, repr=False, compare=False)
21
+
22
+ @property
23
+ def attempts(self) -> int:
24
+ """Use the active delivery count in TaskContext; otherwise Django's count."""
25
+ if self._current_attempt is not None:
26
+ return self._current_attempt
27
+ return len(self.worker_ids)
28
+
29
+
30
+ __all__ = ["TaskferryTaskResult"]
@@ -1,36 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to `taskferry-django` are documented here.
4
- The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
- this project adheres to [Semantic Versioning](https://semver.org/).
6
-
7
- ## [0.2.0] — 2026-07-26
8
-
9
- ### Changed
10
-
11
- - **BREAKING**: `taskferry.django` is now `taskferry_django`.
12
- - Reduced to a pure bridge. `TaskferryBackend` is a `django.tasks` backend that
13
- translates to `TaskSpec` and hands it to a Taskferry runtime; the engine is a
14
- configuration choice, not a Django class.
15
- - Feature flags and capabilities now come from the *routed* backend rather than
16
- being hardcoded per class.
17
-
18
- ### Added
19
-
20
- - `config_from_settings()` — the only place in the project that reads
21
- `django.conf.settings`.
22
- - `submit_on_commit()` / `task_on_commit()`, built on `transaction.on_commit`.
23
- - System checks that build every configured backend at `manage.py check` time.
24
- - `manage.py taskferry <subcommand>`, wrapping the same CLI.
25
- - `taskferry_django.execute:run_task`, the single worker-side dispatcher.
26
-
27
- ### Removed
28
-
29
- - **BREAKING**: the Django-coupled provider backends. Cloud Tasks and
30
- Procrastinate moved to their own framework-agnostic distributions; SQS, Azure
31
- Service Bus and Dramatiq were removed pending a proper port. See the
32
- [migration guide](../../docs/migration/0.1-to-0.2.md).
33
- - `taskferry.django.views.task_webhook` — replaced by
34
- `taskferry_cloudtasks.handle_request`, which takes bytes and works in any
35
- framework.
36
- - `TaskCapability` — use `taskferry.Capability`.
@@ -1,132 +0,0 @@
1
- Metadata-Version: 2.5
2
- Name: taskferry-django
3
- Version: 0.2.0
4
- Summary: Django integration for Taskferry — a django.tasks backend, settings, checks and CLI.
5
- Project-URL: Homepage, https://github.com/xiidigital/taskferry
6
- Project-URL: Documentation, https://taskferry.dev/django
7
- Project-URL: Source, https://github.com/xiidigital/taskferry
8
- Author: Taskferry authors
9
- License-Expression: Apache-2.0
10
- License-File: LICENSE
11
- Keywords: cloud-tasks,django,django-tasks,sqs,taskferry
12
- Classifier: Development Status :: 3 - Alpha
13
- Classifier: Framework :: Django
14
- Classifier: Framework :: Django :: 6.0
15
- Classifier: Intended Audience :: Developers
16
- Classifier: License :: OSI Approved :: Apache Software License
17
- Classifier: Programming Language :: Python :: 3 :: Only
18
- Classifier: Typing :: Typed
19
- Requires-Python: >=3.12
20
- Requires-Dist: django>=5.1
21
- Requires-Dist: taskferry<0.3,>=0.2
22
- Description-Content-Type: text/markdown
23
-
24
- # taskferry-django
25
-
26
- Django integration for [Taskferry](https://github.com/xiidigital/taskferry).
27
-
28
- ```mermaid
29
- flowchart BT
30
- DJ["Django"]
31
- TPD["taskferry-django"]
32
- TP["taskferry"]
33
-
34
- DJ --> TPD --> TP
35
- ```
36
-
37
- Taskferry does **not** invent a parallel task API — Django 6 already has one. This
38
- package supplies a backend for the standard `TASKS` setting, so your `@task` code
39
- never changes while the engine behind it becomes a configuration choice.
40
-
41
- ```bash
42
- pip install taskferry-django taskferry-procrastinate
43
- ```
44
-
45
- ## Your code never changes
46
-
47
- ```python
48
- # myapp/tasks.py
49
- from django.tasks import task
50
-
51
-
52
- @task
53
- def resize_image(image_id: int) -> None: ...
54
- ```
55
-
56
- ```python
57
- # anywhere
58
- resize_image.enqueue(42)
59
- ```
60
-
61
- ## Settings
62
-
63
- ```python
64
- TASKS = {"default": {"BACKEND": "taskferry_django.TaskferryBackend"}}
65
-
66
- TASKFERRY = {
67
- "backends": {
68
- "pg": {"factory": "procrastinate", "app": "myapp.tasks:app"},
69
- "heavy": {"factory": "cloudrun", "project": "p", "location": "europe-west1"},
70
- },
71
- "routes": [
72
- {"kind": "task", "queue": "metadata", "backend": "pg"},
73
- {"kind": "job", "profile": "heavy", "backend": "heavy"},
74
- ],
75
- "defaults": {"task": "pg", "job": "heavy"},
76
- }
77
- ```
78
-
79
- With no `TASKFERRY` setting at all, everything runs locally — a fresh project works
80
- immediately and is obviously not production.
81
-
82
- ## What else you get
83
-
84
- **Enqueue after commit.** The classic race — a worker reaching a row before the
85
- transaction that created it commits — with the classic fix:
86
-
87
- ```python
88
- from django.db import transaction
89
- from taskferry_django import task_on_commit
90
-
91
-
92
- def create_order(request):
93
- with transaction.atomic():
94
- order = Order.objects.create(...)
95
- task_on_commit("myapp.tasks:process_order", order.id)
96
- ```
97
-
98
- **System checks.** `manage.py check` builds every configured backend, because
99
- "the adapter is installed" and "the adapter works with these options" are
100
- different questions:
101
-
102
- ```text
103
- taskferry.E002 the Taskferry backend 'heavy' cannot be built: CloudRunJobBackend
104
- needs both 'project' and 'location'
105
- taskferry.W003 DEBUG is False but these Taskferry backends run in this process and
106
- lose pending work on restart: fast
107
- ```
108
-
109
- **The CLI, with settings loaded.**
110
-
111
- ```bash
112
- python manage.py taskferry doctor
113
- python manage.py taskferry capabilities pg
114
- ```
115
-
116
- **Jobs and inline execution**, through the same runtime:
117
-
118
- ```python
119
- from taskferry_django import get_runtime
120
-
121
- get_runtime().jobs.submit("build-cog", image="gdal:latest", profile="heavy")
122
- ```
123
-
124
- ## The dependency direction
125
-
126
- `taskferry` never imports Django. The test suite for the core runs — and CI runs
127
- it — in an environment where Django is not installed. The same `TASKFERRY` dict
128
- works verbatim in a FastAPI service, a CLI or a library.
129
-
130
- ## License
131
-
132
- Apache-2.0.
@@ -1,109 +0,0 @@
1
- # taskferry-django
2
-
3
- Django integration for [Taskferry](https://github.com/xiidigital/taskferry).
4
-
5
- ```mermaid
6
- flowchart BT
7
- DJ["Django"]
8
- TPD["taskferry-django"]
9
- TP["taskferry"]
10
-
11
- DJ --> TPD --> TP
12
- ```
13
-
14
- Taskferry does **not** invent a parallel task API — Django 6 already has one. This
15
- package supplies a backend for the standard `TASKS` setting, so your `@task` code
16
- never changes while the engine behind it becomes a configuration choice.
17
-
18
- ```bash
19
- pip install taskferry-django taskferry-procrastinate
20
- ```
21
-
22
- ## Your code never changes
23
-
24
- ```python
25
- # myapp/tasks.py
26
- from django.tasks import task
27
-
28
-
29
- @task
30
- def resize_image(image_id: int) -> None: ...
31
- ```
32
-
33
- ```python
34
- # anywhere
35
- resize_image.enqueue(42)
36
- ```
37
-
38
- ## Settings
39
-
40
- ```python
41
- TASKS = {"default": {"BACKEND": "taskferry_django.TaskferryBackend"}}
42
-
43
- TASKFERRY = {
44
- "backends": {
45
- "pg": {"factory": "procrastinate", "app": "myapp.tasks:app"},
46
- "heavy": {"factory": "cloudrun", "project": "p", "location": "europe-west1"},
47
- },
48
- "routes": [
49
- {"kind": "task", "queue": "metadata", "backend": "pg"},
50
- {"kind": "job", "profile": "heavy", "backend": "heavy"},
51
- ],
52
- "defaults": {"task": "pg", "job": "heavy"},
53
- }
54
- ```
55
-
56
- With no `TASKFERRY` setting at all, everything runs locally — a fresh project works
57
- immediately and is obviously not production.
58
-
59
- ## What else you get
60
-
61
- **Enqueue after commit.** The classic race — a worker reaching a row before the
62
- transaction that created it commits — with the classic fix:
63
-
64
- ```python
65
- from django.db import transaction
66
- from taskferry_django import task_on_commit
67
-
68
-
69
- def create_order(request):
70
- with transaction.atomic():
71
- order = Order.objects.create(...)
72
- task_on_commit("myapp.tasks:process_order", order.id)
73
- ```
74
-
75
- **System checks.** `manage.py check` builds every configured backend, because
76
- "the adapter is installed" and "the adapter works with these options" are
77
- different questions:
78
-
79
- ```text
80
- taskferry.E002 the Taskferry backend 'heavy' cannot be built: CloudRunJobBackend
81
- needs both 'project' and 'location'
82
- taskferry.W003 DEBUG is False but these Taskferry backends run in this process and
83
- lose pending work on restart: fast
84
- ```
85
-
86
- **The CLI, with settings loaded.**
87
-
88
- ```bash
89
- python manage.py taskferry doctor
90
- python manage.py taskferry capabilities pg
91
- ```
92
-
93
- **Jobs and inline execution**, through the same runtime:
94
-
95
- ```python
96
- from taskferry_django import get_runtime
97
-
98
- get_runtime().jobs.submit("build-cog", image="gdal:latest", profile="heavy")
99
- ```
100
-
101
- ## The dependency direction
102
-
103
- `taskferry` never imports Django. The test suite for the core runs — and CI runs
104
- it — in an environment where Django is not installed. The same `TASKFERRY` dict
105
- works verbatim in a FastAPI service, a CLI or a library.
106
-
107
- ## License
108
-
109
- Apache-2.0.