taskferry-django 0.2.0__tar.gz → 0.3.0__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.2.0 → taskferry_django-0.3.0}/CHANGELOG.md +18 -9
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/PKG-INFO +58 -8
- taskferry_django-0.3.0/README.md +159 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/pyproject.toml +2 -2
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/backend.py +13 -12
- taskferry_django-0.2.0/README.md +0 -109
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/.gitignore +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/LICENSE +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/__init__.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/apps.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/checks.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/config.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/execute.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/management/__init__.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/management/commands/__init__.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/management/commands/taskferry.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/py.typed +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/transaction.py +0 -0
- {taskferry_django-0.2.0 → taskferry_django-0.3.0}/src/taskferry_django/views.py +0 -0
|
@@ -4,11 +4,22 @@ All notable changes to `taskferry-django` are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
5
|
this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## Unreleased
|
|
8
|
+
|
|
9
|
+
## [0.3.0] — 2026-11-26
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- **BREAKING**: Require Django 6.0+, matching the native `django.tasks` imports.
|
|
14
|
+
The package does not target the third-party backport on Django 5.x.
|
|
15
|
+
- Do not advertise `supports_async_task` or `supports_get_result`: the dispatcher
|
|
16
|
+
is synchronous and the bridge does not persist Django-specific `TaskResult`
|
|
17
|
+
records. Calling `get_result()` raises `NotImplementedError`.
|
|
18
|
+
|
|
7
19
|
## [0.2.0] — 2026-07-26
|
|
8
20
|
|
|
9
21
|
### Changed
|
|
10
22
|
|
|
11
|
-
- **BREAKING**: `taskferry.django` is now `taskferry_django`.
|
|
12
23
|
- Reduced to a pure bridge. `TaskferryBackend` is a `django.tasks` backend that
|
|
13
24
|
translates to `TaskSpec` and hands it to a Taskferry runtime; the engine is a
|
|
14
25
|
configuration choice, not a Django class.
|
|
@@ -26,11 +37,9 @@ this project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
26
37
|
|
|
27
38
|
### Removed
|
|
28
39
|
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
framework.
|
|
36
|
-
- `TaskCapability` — use `taskferry.Capability`.
|
|
40
|
+
- Provider integrations are maintained by their dedicated distributions,
|
|
41
|
+
including `taskferry-cloudtasks`, `taskferry-procrastinate`, `taskferry-sqs`,
|
|
42
|
+
`taskferry-servicebus`, and `taskferry-dramatiq`.
|
|
43
|
+
- The Cloud Tasks request handler is available as
|
|
44
|
+
`taskferry_cloudtasks.handle_request` and accepts request bytes.
|
|
45
|
+
- Backend support is described by `taskferry.Capability`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: taskferry-django
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
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
|
|
@@ -17,7 +17,7 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
18
|
Classifier: Typing :: Typed
|
|
19
19
|
Requires-Python: >=3.12
|
|
20
|
-
Requires-Dist: django>=
|
|
20
|
+
Requires-Dist: django>=6.0
|
|
21
21
|
Requires-Dist: taskferry<0.3,>=0.2
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
23
23
|
|
|
@@ -34,7 +34,9 @@ flowchart BT
|
|
|
34
34
|
DJ --> TPD --> TP
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
This package supports **Django 6.0+ native `django.tasks`**. Django introduced
|
|
38
|
+
that API in 6.0; this package imports it directly and does not integrate the
|
|
39
|
+
third-party `django-tasks` backport. Taskferry does **not** invent a parallel API. This
|
|
38
40
|
package supplies a backend for the standard `TASKS` setting, so your `@task` code
|
|
39
41
|
never changes while the engine behind it becomes a configuration choice.
|
|
40
42
|
|
|
@@ -65,20 +67,68 @@ TASKS = {"default": {"BACKEND": "taskferry_django.TaskferryBackend"}}
|
|
|
65
67
|
|
|
66
68
|
TASKFERRY = {
|
|
67
69
|
"backends": {
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
+
"celery": {"factory": "celery", "app": "myproject.celery:app"},
|
|
71
|
+
"gcp": {
|
|
72
|
+
"factory": "cloudtasks",
|
|
73
|
+
"project": "my-project",
|
|
74
|
+
"location": "us-central1",
|
|
75
|
+
"url": "https://example.run.app/_taskferry/execute",
|
|
76
|
+
},
|
|
70
77
|
},
|
|
71
78
|
"routes": [
|
|
72
|
-
{"kind": "task", "queue": "
|
|
73
|
-
{"kind": "
|
|
79
|
+
{"kind": "task", "queue": "local-workers", "backend": "celery"},
|
|
80
|
+
{"kind": "task", "queue": "serverless", "backend": "gcp"},
|
|
74
81
|
],
|
|
75
|
-
"defaults": {"task": "
|
|
82
|
+
"defaults": {"task": "celery"},
|
|
76
83
|
}
|
|
77
84
|
```
|
|
78
85
|
|
|
86
|
+
For Celery, configure broker/result storage on `myproject.celery:app` itself;
|
|
87
|
+
the backend name in Taskferry chooses the Celery execution adapter, while Celery
|
|
88
|
+
chooses its broker and optional result store. Change the queue routes or default
|
|
89
|
+
to move Django tasks between Celery and Cloud Tasks without changing task code.
|
|
90
|
+
|
|
79
91
|
With no `TASKFERRY` setting at all, everything runs locally — a fresh project works
|
|
80
92
|
immediately and is obviously not production.
|
|
81
93
|
|
|
94
|
+
### Choosing execution and storage
|
|
95
|
+
|
|
96
|
+
Choose an engine through `TASKFERRY.backends` and route queues with the usual
|
|
97
|
+
`routes`/`defaults` configuration. Django's native Tasks API is the enqueue
|
|
98
|
+
interface; it does not include a production queue or durable task store. Provider
|
|
99
|
+
integrations are separate optional distributions:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pip install taskferry-django taskferry-celery[celery]
|
|
103
|
+
# If Redis is your chosen Celery broker and/or result backend:
|
|
104
|
+
pip install 'taskferry-celery[redis]'
|
|
105
|
+
# If RabbitMQ is your chosen Celery broker:
|
|
106
|
+
pip install 'taskferry-celery[rabbitmq]'
|
|
107
|
+
# For GCP push delivery:
|
|
108
|
+
pip install taskferry-django 'taskferry-cloudtasks[gcp]'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Celery's broker and result backend are configured on the Celery app, independently
|
|
112
|
+
of Taskferry routing. Redis is optional; Celery can use other supported brokers
|
|
113
|
+
and result stores, or run without result storage. The `rabbitmq` extra is an
|
|
114
|
+
installation alias; Celery includes its AMQP transport. RabbitMQ can also use
|
|
115
|
+
Celery's transient `rpc://` result backend, or pair with a separate database
|
|
116
|
+
result backend. The Taskferry Celery adapter
|
|
117
|
+
advertises result retrieval only when `app.conf.result_backend` is configured.
|
|
118
|
+
Cloud Tasks is a push queue: it cannot report execution state or persist return
|
|
119
|
+
values, so persist progress and results in application-owned storage if required.
|
|
120
|
+
|
|
121
|
+
Taskferry serializes task names and arguments as JSON; pass identifiers or other
|
|
122
|
+
JSON-safe values, never ORM instances or pickled objects. Cloud Tasks provides
|
|
123
|
+
time-bounded task-name deduplication when an idempotency key is supplied; Celery
|
|
124
|
+
does not, so keyed submissions are rejected there. Cloud Tasks and Celery retry
|
|
125
|
+
through their native engines according to the Taskferry retry policy. Delivery
|
|
126
|
+
can be duplicated: make task handlers idempotent. Celery revoke is best effort
|
|
127
|
+
and does not interrupt a running handler; Cloud Tasks does not expose cancellation.
|
|
128
|
+
Taskferry has no portable progress reporting contract yet. Celery's persisted
|
|
129
|
+
state can show queued/started/terminal state when configured, but richer progress
|
|
130
|
+
belongs in application storage.
|
|
131
|
+
|
|
82
132
|
## What else you get
|
|
83
133
|
|
|
84
134
|
**Enqueue after commit.** The classic race — a worker reaching a row before the
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
## What else you get
|
|
110
|
+
|
|
111
|
+
**Enqueue after commit.** The classic race — a worker reaching a row before the
|
|
112
|
+
transaction that created it commits — with the classic fix:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from django.db import transaction
|
|
116
|
+
from taskferry_django import task_on_commit
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def create_order(request):
|
|
120
|
+
with transaction.atomic():
|
|
121
|
+
order = Order.objects.create(...)
|
|
122
|
+
task_on_commit("myapp.tasks:process_order", order.id)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**System checks.** `manage.py check` builds every configured backend, because
|
|
126
|
+
"the adapter is installed" and "the adapter works with these options" are
|
|
127
|
+
different questions:
|
|
128
|
+
|
|
129
|
+
```text
|
|
130
|
+
taskferry.E002 the Taskferry backend 'heavy' cannot be built: CloudRunJobBackend
|
|
131
|
+
needs both 'project' and 'location'
|
|
132
|
+
taskferry.W003 DEBUG is False but these Taskferry backends run in this process and
|
|
133
|
+
lose pending work on restart: fast
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**The CLI, with settings loaded.**
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
python manage.py taskferry doctor
|
|
140
|
+
python manage.py taskferry capabilities pg
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Jobs and inline execution**, through the same runtime:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from taskferry_django import get_runtime
|
|
147
|
+
|
|
148
|
+
get_runtime().jobs.submit("build-cog", image="gdal:latest", profile="heavy")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## The dependency direction
|
|
152
|
+
|
|
153
|
+
`taskferry` never imports Django. The test suite for the core runs — and CI runs
|
|
154
|
+
it — in an environment where Django is not installed. The same `TASKFERRY` dict
|
|
155
|
+
works verbatim in a FastAPI service, a CLI or a library.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
Apache-2.0.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "taskferry-django"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
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"
|
|
@@ -21,7 +21,7 @@ classifiers = [
|
|
|
21
21
|
"Programming Language :: Python :: 3 :: Only",
|
|
22
22
|
"Typing :: Typed",
|
|
23
23
|
]
|
|
24
|
-
dependencies = ["taskferry>=0.2,<0.3", "django>=
|
|
24
|
+
dependencies = ["taskferry>=0.2,<0.3", "django>=6.0"]
|
|
25
25
|
|
|
26
26
|
[project.urls]
|
|
27
27
|
Homepage = "https://github.com/xiidigital/taskferry"
|
|
@@ -32,7 +32,6 @@ from django.tasks.backends.base import BaseTaskBackend
|
|
|
32
32
|
from django.tasks.base import Task, TaskResult, TaskResultStatus
|
|
33
33
|
|
|
34
34
|
from taskferry import CapabilitySet, ExecutionState, Taskferry, TaskSpec
|
|
35
|
-
from taskferry.errors import TaskferryError
|
|
36
35
|
|
|
37
36
|
from .config import get_runtime
|
|
38
37
|
from .execute import DISPATCH_REF
|
|
@@ -75,8 +74,11 @@ class TaskferryBackend(BaseTaskBackend):
|
|
|
75
74
|
#: permissively and the real, per-backend answer is enforced at submit time
|
|
76
75
|
#: by the capability check, which raises rather than silently degrading.
|
|
77
76
|
supports_defer = True
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
# The dispatcher invokes Task.call() synchronously and the portable runtime
|
|
78
|
+
# has no durable Django TaskResult store. Do not advertise features we cannot
|
|
79
|
+
# guarantee across workers or process restarts.
|
|
80
|
+
supports_async_task = False
|
|
81
|
+
supports_get_result = False
|
|
80
82
|
supports_priority = True
|
|
81
83
|
|
|
82
84
|
def __init__(self, alias: str, params: dict[str, Any]) -> None:
|
|
@@ -178,17 +180,16 @@ class TaskferryBackend(BaseTaskBackend):
|
|
|
178
180
|
)
|
|
179
181
|
|
|
180
182
|
def get_result(self, result_id: str) -> TaskResult:
|
|
181
|
-
"""
|
|
183
|
+
"""Django result lookup is not backed by durable task metadata here.
|
|
182
184
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
Django Tasks requires a stored ``TaskResult`` including its original Task
|
|
186
|
+
object, arguments, attempts, and errors. The portable execution backends
|
|
187
|
+
do not persist that Django-specific record, so pretending a Taskferry
|
|
188
|
+
execution lookup is equivalent would return incomplete or fabricated data.
|
|
187
189
|
"""
|
|
188
|
-
raise
|
|
189
|
-
"
|
|
190
|
-
"runtime
|
|
191
|
-
"are visible and an unsupported lookup fails honestly"
|
|
190
|
+
raise NotImplementedError(
|
|
191
|
+
f"Taskferry does not persist Django TaskResult records (id={result_id!r}); "
|
|
192
|
+
"use the Taskferry runtime and its configured backend capabilities"
|
|
192
193
|
)
|
|
193
194
|
|
|
194
195
|
|
taskferry_django-0.2.0/README.md
DELETED
|
@@ -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.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{taskferry_django-0.2.0 → taskferry_django-0.3.0}/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
|