taskferry-django 0.3.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.
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/CHANGELOG.md +12 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/PKG-INFO +23 -1
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/README.md +21 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/pyproject.toml +2 -1
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/__init__.py +3 -1
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/backend.py +11 -4
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/execute.py +37 -3
- taskferry_django-0.3.1/src/taskferry_django/results.py +30 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/.gitignore +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/LICENSE +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/apps.py +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/checks.py +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/config.py +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/management/__init__.py +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/management/commands/__init__.py +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/management/commands/taskferry.py +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/py.typed +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/transaction.py +0 -0
- {taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/views.py +0 -0
|
@@ -6,6 +6,18 @@ this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
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
|
+
|
|
9
21
|
## [0.3.0] — 2026-11-26
|
|
10
22
|
|
|
11
23
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: taskferry-django
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Django integration for Taskferry — a django.tasks backend, settings, checks and CLI.
|
|
5
5
|
Project-URL: Homepage, https://github.com/xiidigital/taskferry
|
|
6
6
|
Project-URL: Documentation, https://taskferry.dev/django
|
|
@@ -12,6 +12,7 @@ Keywords: cloud-tasks,django,django-tasks,sqs,taskferry
|
|
|
12
12
|
Classifier: Development Status :: 3 - Alpha
|
|
13
13
|
Classifier: Framework :: Django
|
|
14
14
|
Classifier: Framework :: Django :: 6.0
|
|
15
|
+
Classifier: Framework :: Django :: 6.1
|
|
15
16
|
Classifier: Intended Audience :: Developers
|
|
16
17
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
18
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
@@ -129,6 +130,27 @@ Taskferry has no portable progress reporting contract yet. Celery's persisted
|
|
|
129
130
|
state can show queued/started/terminal state when configured, but richer progress
|
|
130
131
|
belongs in application storage.
|
|
131
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
|
+
|
|
132
154
|
## What else you get
|
|
133
155
|
|
|
134
156
|
**Enqueue after commit.** The classic race — a worker reaching a row before the
|
|
@@ -106,6 +106,27 @@ Taskferry has no portable progress reporting contract yet. Celery's persisted
|
|
|
106
106
|
state can show queued/started/terminal state when configured, but richer progress
|
|
107
107
|
belongs in application storage.
|
|
108
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
|
+
|
|
109
130
|
## What else you get
|
|
110
131
|
|
|
111
132
|
**Enqueue after commit.** The classic race — a worker reaching a row before the
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "taskferry-django"
|
|
7
|
-
version = "0.3.
|
|
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,6 +16,7 @@ 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",
|
|
@@ -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.
|
|
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,10 +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
|
|
34
|
+
from taskferry import Capability, CapabilitySet, ExecutionKind, ExecutionState, Taskferry, TaskSpec
|
|
35
|
+
from taskferry.execution import new_execution_id
|
|
35
36
|
|
|
36
37
|
from .config import get_runtime
|
|
37
38
|
from .execute import DISPATCH_REF
|
|
39
|
+
from .results import TaskferryTaskResult
|
|
38
40
|
|
|
39
41
|
#: Portable state -> the Django Tasks status vocabulary. Django's enum is
|
|
40
42
|
#: coarser than Taskferry's, so several states collapse; the mapping is written
|
|
@@ -127,6 +129,9 @@ class TaskferryBackend(BaseTaskBackend):
|
|
|
127
129
|
"""Translate a Django task into a spec and submit it."""
|
|
128
130
|
self.validate_task(task)
|
|
129
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)
|
|
130
135
|
handle = self.runtime.submit(spec, backend=self._pinned)
|
|
131
136
|
return self._task_result(task, args, kwargs, handle.execution)
|
|
132
137
|
|
|
@@ -150,6 +155,7 @@ class TaskferryBackend(BaseTaskBackend):
|
|
|
150
155
|
run_at=task.run_after,
|
|
151
156
|
name=task.name,
|
|
152
157
|
labels={"django_task": task.module_path},
|
|
158
|
+
execution_id=(new_execution_id(ExecutionKind.TASK) if task.takes_context else None),
|
|
153
159
|
)
|
|
154
160
|
|
|
155
161
|
def _task_result(
|
|
@@ -158,10 +164,10 @@ class TaskferryBackend(BaseTaskBackend):
|
|
|
158
164
|
args: list[Any],
|
|
159
165
|
kwargs: dict[str, Any],
|
|
160
166
|
execution: Any,
|
|
161
|
-
) ->
|
|
167
|
+
) -> TaskferryTaskResult:
|
|
162
168
|
from django.utils import timezone
|
|
163
169
|
|
|
164
|
-
return
|
|
170
|
+
return TaskferryTaskResult(
|
|
165
171
|
task=task,
|
|
166
172
|
# Django caps result ids at 64 characters; a Taskferry id is well
|
|
167
173
|
# inside that, which is one reason ids are minted rather than
|
|
@@ -177,6 +183,7 @@ class TaskferryBackend(BaseTaskBackend):
|
|
|
177
183
|
backend=self.alias,
|
|
178
184
|
errors=[],
|
|
179
185
|
worker_ids=[],
|
|
186
|
+
provider_id=execution.external_id,
|
|
180
187
|
)
|
|
181
188
|
|
|
182
189
|
def get_result(self, result_id: str) -> TaskResult:
|
|
@@ -193,4 +200,4 @@ class TaskferryBackend(BaseTaskBackend):
|
|
|
193
200
|
)
|
|
194
201
|
|
|
195
202
|
|
|
196
|
-
__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
|
-
|
|
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"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{taskferry_django-0.3.0 → taskferry_django-0.3.1}/src/taskferry_django/management/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|