taskferry-celery 0.1.0__tar.gz → 0.2.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_celery-0.1.0 → taskferry_celery-0.2.1}/CHANGELOG.md +24 -0
- taskferry_celery-0.2.1/PKG-INFO +131 -0
- taskferry_celery-0.2.1/README.md +103 -0
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/pyproject.toml +3 -1
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/src/taskferry_celery/__init__.py +1 -1
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/src/taskferry_celery/backend.py +48 -7
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/src/taskferry_celery/worker.py +11 -3
- taskferry_celery-0.1.0/PKG-INFO +0 -87
- taskferry_celery-0.1.0/README.md +0 -63
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/.gitignore +0 -0
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/LICENSE +0 -0
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/src/taskferry_celery/message.py +0 -0
- {taskferry_celery-0.1.0 → taskferry_celery-0.2.1}/src/taskferry_celery/py.typed +0 -0
|
@@ -3,6 +3,30 @@
|
|
|
3
3
|
Follows [Semantic Versioning](https://semver.org/); versions independently of the
|
|
4
4
|
rest of the family.
|
|
5
5
|
|
|
6
|
+
## Unreleased
|
|
7
|
+
|
|
8
|
+
## [0.2.1] — 2026-11-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Propagate Celery's current retry number and worker hostname into execution
|
|
13
|
+
context for adapters such as `taskferry-django`.
|
|
14
|
+
- Align `taskferry_celery.__version__` with the distribution version `0.2.1`.
|
|
15
|
+
|
|
16
|
+
## [0.2.0] — 2026-11-26
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Advertise `RESULT` only when the configured Celery app has a result backend,
|
|
21
|
+
and read successful values and failures from that backend.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- A `redis` extra for deployments that choose Redis as Celery broker or result
|
|
26
|
+
backend. Celery and Redis remain optional dependencies.
|
|
27
|
+
- A `rabbitmq` convenience extra; RabbitMQ uses Celery's built-in AMQP transport
|
|
28
|
+
and does not add a separate provider dependency.
|
|
29
|
+
|
|
6
30
|
## [0.1.0]
|
|
7
31
|
|
|
8
32
|
### Added
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: taskferry-celery
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Celery task backend for Taskferry — enqueue Taskferry tasks onto a Celery app.
|
|
5
|
+
Project-URL: Homepage, https://github.com/xiidigital/taskferry
|
|
6
|
+
Project-URL: Documentation, https://taskferry.dev
|
|
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: celery,queue,taskferry,tasks
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Requires-Dist: taskferry<0.3,>=0.2
|
|
21
|
+
Provides-Extra: celery
|
|
22
|
+
Requires-Dist: celery>=5.3; extra == 'celery'
|
|
23
|
+
Provides-Extra: rabbitmq
|
|
24
|
+
Requires-Dist: celery>=5.3; extra == 'rabbitmq'
|
|
25
|
+
Provides-Extra: redis
|
|
26
|
+
Requires-Dist: celery[redis]>=5.3; extra == 'redis'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# taskferry-celery
|
|
30
|
+
|
|
31
|
+
A **Celery** task backend for [Taskferry](https://taskferry.dev). Enqueue Taskferry
|
|
32
|
+
tasks onto a Celery app you already run; Taskferry supplies no worker and
|
|
33
|
+
reimplements none of Celery.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install taskferry-celery[celery]
|
|
37
|
+
# Optional Redis transport/result backend support:
|
|
38
|
+
pip install taskferry-celery[redis]
|
|
39
|
+
# Optional convenience alias when the Celery broker is RabbitMQ:
|
|
40
|
+
pip install taskferry-celery[rabbitmq]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Submitting
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from taskferry import Taskferry
|
|
47
|
+
|
|
48
|
+
runtime = Taskferry.from_mapping(
|
|
49
|
+
{
|
|
50
|
+
"backends": {"cel": {"factory": "celery", "app": "myapp.celery:app"}},
|
|
51
|
+
"defaults": {"task": "cel"},
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
runtime.tasks.submit("myapp.tasks:refresh", 42, queue="metadata")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Executing (worker)
|
|
58
|
+
|
|
59
|
+
Register the dispatcher once, then run Celery's own worker:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from celery import Celery
|
|
63
|
+
from taskferry_celery import register_dispatcher
|
|
64
|
+
from taskferry.functions import FunctionRegistry
|
|
65
|
+
|
|
66
|
+
app = Celery("myapp", broker="redis://localhost:6379/0")
|
|
67
|
+
# Result storage is independent from the broker and optional.
|
|
68
|
+
app.conf.result_backend = "redis://localhost:6379/1"
|
|
69
|
+
app.conf.task_serializer = "json"
|
|
70
|
+
app.conf.result_serializer = "json"
|
|
71
|
+
app.conf.accept_content = ["json"]
|
|
72
|
+
register_dispatcher(app, registry=FunctionRegistry(allowed_modules=["myapp"]))
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
RabbitMQ uses Celery's built-in AMQP transport; the `rabbitmq` extra is a
|
|
76
|
+
convenience installation alias for Celery and does not install Redis or a
|
|
77
|
+
separate RabbitMQ client:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
app = Celery(
|
|
81
|
+
"myapp",
|
|
82
|
+
broker="amqp://taskferry:secret@rabbitmq:5672/myvhost",
|
|
83
|
+
backend="rpc://", # optional result store over AMQP; results are transient
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
RabbitMQ as a broker does not by itself store task results. Configure a Celery
|
|
88
|
+
result backend separately if `TaskferryBackend.result()` is needed. The RPC
|
|
89
|
+
backend can avoid Redis for result delivery; Celery also supports database and
|
|
90
|
+
other result backends.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
celery -A myapp worker
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Capabilities (honest)
|
|
97
|
+
|
|
98
|
+
| Advertised | Conditional / unavailable | Why |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| submit, state, cancel, delay, priority, retry | `result` only when `app.conf.result_backend` is set | Celery discards return values when result storage is disabled |
|
|
101
|
+
| | `deduplication` | Celery has no native mechanism — an `idempotency_key` is rejected, not ignored |
|
|
102
|
+
|
|
103
|
+
Retries are the **engine's**: the dispatcher raises Celery's own `self.retry`, so
|
|
104
|
+
a failed task is genuinely re-queued with the requested countdown. Taskferry never
|
|
105
|
+
loops in-process pretending to retry.
|
|
106
|
+
|
|
107
|
+
`state` maps Celery's `PENDING/STARTED/SUCCESS/FAILURE/RETRY/REVOKED` onto the
|
|
108
|
+
portable states. Set Celery's `task_track_started` if workers should persist the
|
|
109
|
+
`STARTED` state. Celery reports `PENDING` for both a queued task and an unknown
|
|
110
|
+
id, so those remain indistinguishable. `result()` reads Celery's configured
|
|
111
|
+
result backend; that can be Redis, a database or another Celery-supported store.
|
|
112
|
+
The Redis extra is optional, and Redis is not required as either broker or result
|
|
113
|
+
storage. The result store persists Celery's result, but Taskferry's own
|
|
114
|
+
Taskferry-id-to-Celery-id index is process-local. For cross-process lookups, keep
|
|
115
|
+
the Celery task id (`Execution.external_id`) and pass it to
|
|
116
|
+
`runtime.get(celery_id, backend="celery")`; a Django `TaskResult` lookup is not
|
|
117
|
+
provided by the bridge.
|
|
118
|
+
|
|
119
|
+
Delivery is at least once: workers can redeliver after a crash or lost ack. Make
|
|
120
|
+
handlers idempotent. Taskferry retry policy is translated to Celery retries, with
|
|
121
|
+
Celery as the sole retry owner. Revocation is best effort and cannot stop code
|
|
122
|
+
already running. Result backends store a task's final return/error; Taskferry does
|
|
123
|
+
not define a provider-neutral progress schema, so persist domain progress in your
|
|
124
|
+
application store.
|
|
125
|
+
|
|
126
|
+
Only JSON-safe arguments and a `"module:function"` name cross the wire — never a
|
|
127
|
+
pickled callable.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
Apache-2.0.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# taskferry-celery
|
|
2
|
+
|
|
3
|
+
A **Celery** task backend for [Taskferry](https://taskferry.dev). Enqueue Taskferry
|
|
4
|
+
tasks onto a Celery app you already run; Taskferry supplies no worker and
|
|
5
|
+
reimplements none of Celery.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install taskferry-celery[celery]
|
|
9
|
+
# Optional Redis transport/result backend support:
|
|
10
|
+
pip install taskferry-celery[redis]
|
|
11
|
+
# Optional convenience alias when the Celery broker is RabbitMQ:
|
|
12
|
+
pip install taskferry-celery[rabbitmq]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Submitting
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from taskferry import Taskferry
|
|
19
|
+
|
|
20
|
+
runtime = Taskferry.from_mapping(
|
|
21
|
+
{
|
|
22
|
+
"backends": {"cel": {"factory": "celery", "app": "myapp.celery:app"}},
|
|
23
|
+
"defaults": {"task": "cel"},
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
runtime.tasks.submit("myapp.tasks:refresh", 42, queue="metadata")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Executing (worker)
|
|
30
|
+
|
|
31
|
+
Register the dispatcher once, then run Celery's own worker:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from celery import Celery
|
|
35
|
+
from taskferry_celery import register_dispatcher
|
|
36
|
+
from taskferry.functions import FunctionRegistry
|
|
37
|
+
|
|
38
|
+
app = Celery("myapp", broker="redis://localhost:6379/0")
|
|
39
|
+
# Result storage is independent from the broker and optional.
|
|
40
|
+
app.conf.result_backend = "redis://localhost:6379/1"
|
|
41
|
+
app.conf.task_serializer = "json"
|
|
42
|
+
app.conf.result_serializer = "json"
|
|
43
|
+
app.conf.accept_content = ["json"]
|
|
44
|
+
register_dispatcher(app, registry=FunctionRegistry(allowed_modules=["myapp"]))
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
RabbitMQ uses Celery's built-in AMQP transport; the `rabbitmq` extra is a
|
|
48
|
+
convenience installation alias for Celery and does not install Redis or a
|
|
49
|
+
separate RabbitMQ client:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
app = Celery(
|
|
53
|
+
"myapp",
|
|
54
|
+
broker="amqp://taskferry:secret@rabbitmq:5672/myvhost",
|
|
55
|
+
backend="rpc://", # optional result store over AMQP; results are transient
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
RabbitMQ as a broker does not by itself store task results. Configure a Celery
|
|
60
|
+
result backend separately if `TaskferryBackend.result()` is needed. The RPC
|
|
61
|
+
backend can avoid Redis for result delivery; Celery also supports database and
|
|
62
|
+
other result backends.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
celery -A myapp worker
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Capabilities (honest)
|
|
69
|
+
|
|
70
|
+
| Advertised | Conditional / unavailable | Why |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| submit, state, cancel, delay, priority, retry | `result` only when `app.conf.result_backend` is set | Celery discards return values when result storage is disabled |
|
|
73
|
+
| | `deduplication` | Celery has no native mechanism — an `idempotency_key` is rejected, not ignored |
|
|
74
|
+
|
|
75
|
+
Retries are the **engine's**: the dispatcher raises Celery's own `self.retry`, so
|
|
76
|
+
a failed task is genuinely re-queued with the requested countdown. Taskferry never
|
|
77
|
+
loops in-process pretending to retry.
|
|
78
|
+
|
|
79
|
+
`state` maps Celery's `PENDING/STARTED/SUCCESS/FAILURE/RETRY/REVOKED` onto the
|
|
80
|
+
portable states. Set Celery's `task_track_started` if workers should persist the
|
|
81
|
+
`STARTED` state. Celery reports `PENDING` for both a queued task and an unknown
|
|
82
|
+
id, so those remain indistinguishable. `result()` reads Celery's configured
|
|
83
|
+
result backend; that can be Redis, a database or another Celery-supported store.
|
|
84
|
+
The Redis extra is optional, and Redis is not required as either broker or result
|
|
85
|
+
storage. The result store persists Celery's result, but Taskferry's own
|
|
86
|
+
Taskferry-id-to-Celery-id index is process-local. For cross-process lookups, keep
|
|
87
|
+
the Celery task id (`Execution.external_id`) and pass it to
|
|
88
|
+
`runtime.get(celery_id, backend="celery")`; a Django `TaskResult` lookup is not
|
|
89
|
+
provided by the bridge.
|
|
90
|
+
|
|
91
|
+
Delivery is at least once: workers can redeliver after a crash or lost ack. Make
|
|
92
|
+
handlers idempotent. Taskferry retry policy is translated to Celery retries, with
|
|
93
|
+
Celery as the sole retry owner. Revocation is best effort and cannot stop code
|
|
94
|
+
already running. Result backends store a task's final return/error; Taskferry does
|
|
95
|
+
not define a provider-neutral progress schema, so persist domain progress in your
|
|
96
|
+
application store.
|
|
97
|
+
|
|
98
|
+
Only JSON-safe arguments and a `"module:function"` name cross the wire — never a
|
|
99
|
+
pickled callable.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
Apache-2.0.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "taskferry-celery"
|
|
7
|
-
version = "0.1
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Celery task backend for Taskferry — enqueue Taskferry tasks onto a Celery app."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -25,6 +25,8 @@ dependencies = ["taskferry>=0.2,<0.3"]
|
|
|
25
25
|
|
|
26
26
|
[project.optional-dependencies]
|
|
27
27
|
celery = ["celery>=5.3"]
|
|
28
|
+
redis = ["celery[redis]>=5.3"]
|
|
29
|
+
rabbitmq = ["celery>=5.3"]
|
|
28
30
|
|
|
29
31
|
[project.entry-points."taskferry.backends"]
|
|
30
32
|
celery = "taskferry_celery:make_backend"
|
|
@@ -27,11 +27,10 @@ Capabilities are advertised from what Celery genuinely does out of the box:
|
|
|
27
27
|
* ``STATE`` — through ``AsyncResult``;
|
|
28
28
|
* ``CANCEL`` — ``AsyncResult.revoke``.
|
|
29
29
|
|
|
30
|
-
``RESULT`` is
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
``idempotency_key`` is rejected here rather than accepted and ignored.
|
|
30
|
+
``RESULT`` is advertised only when the configured Celery app has a result
|
|
31
|
+
backend. ``DEDUPLICATION`` is not advertised: Celery has no native mechanism for
|
|
32
|
+
it, so a spec carrying an ``idempotency_key`` is rejected rather than accepted
|
|
33
|
+
and ignored.
|
|
35
34
|
|
|
36
35
|
A note on Celery's ``PENDING``: Celery reports ``PENDING`` both for a task that is
|
|
37
36
|
genuinely queued *and* for a task id it has never heard of. Taskferry maps
|
|
@@ -51,6 +50,7 @@ from taskferry.execution import (
|
|
|
51
50
|
Execution,
|
|
52
51
|
ExecutionId,
|
|
53
52
|
ExecutionKind,
|
|
53
|
+
ExecutionResult,
|
|
54
54
|
ExecutionState,
|
|
55
55
|
new_execution_id,
|
|
56
56
|
)
|
|
@@ -71,6 +71,7 @@ CELERY_CAPABILITIES = frozenset(
|
|
|
71
71
|
Capability.DELAY,
|
|
72
72
|
Capability.PRIORITY,
|
|
73
73
|
Capability.RETRY,
|
|
74
|
+
Capability.EXECUTION_CONTEXT,
|
|
74
75
|
}
|
|
75
76
|
)
|
|
76
77
|
|
|
@@ -151,7 +152,23 @@ class CeleryTaskBackend(BaseBackend):
|
|
|
151
152
|
|
|
152
153
|
@property
|
|
153
154
|
def capabilities(self) -> CapabilitySet:
|
|
154
|
-
|
|
155
|
+
capabilities = set(CELERY_CAPABILITIES)
|
|
156
|
+
if self._has_result_backend():
|
|
157
|
+
capabilities.add(Capability.RESULT)
|
|
158
|
+
return CapabilitySet(capabilities, provider=self._name)
|
|
159
|
+
|
|
160
|
+
def _has_result_backend(self) -> bool:
|
|
161
|
+
"""Return whether this app has durable Celery result storage configured.
|
|
162
|
+
|
|
163
|
+
A broker (including Redis) does not imply a result backend. Celery's
|
|
164
|
+
disabled result backend silently discards return values, so RESULT is
|
|
165
|
+
advertised only when ``result_backend`` is set explicitly.
|
|
166
|
+
"""
|
|
167
|
+
if self._app is None:
|
|
168
|
+
return False
|
|
169
|
+
app = self.app()
|
|
170
|
+
conf = getattr(app, "conf", None)
|
|
171
|
+
return bool(getattr(conf, "result_backend", None))
|
|
155
172
|
|
|
156
173
|
# -- the app ---------------------------------------------------------------- #
|
|
157
174
|
def app(self) -> Any:
|
|
@@ -191,7 +208,7 @@ class CeleryTaskBackend(BaseBackend):
|
|
|
191
208
|
) from exc
|
|
192
209
|
|
|
193
210
|
task_id = str(getattr(async_result, "id", "") or "")
|
|
194
|
-
execution_id = new_execution_id(ExecutionKind.TASK)
|
|
211
|
+
execution_id = spec.execution_id or new_execution_id(ExecutionKind.TASK)
|
|
195
212
|
self._ids.remember(str(execution_id), task_id)
|
|
196
213
|
return Execution(
|
|
197
214
|
id=execution_id,
|
|
@@ -234,6 +251,30 @@ class CeleryTaskBackend(BaseBackend):
|
|
|
234
251
|
provider_metadata=ProviderMetadata(provider="celery", provider_id=task_id),
|
|
235
252
|
)
|
|
236
253
|
|
|
254
|
+
def _result(self, execution_id: ExecutionId, *, timeout: float | None) -> ExecutionResult:
|
|
255
|
+
"""Read the value/error from Celery's configured result store."""
|
|
256
|
+
async_result = self._result_handle(execution_id)
|
|
257
|
+
try:
|
|
258
|
+
value = async_result.get(timeout=timeout, propagate=False)
|
|
259
|
+
except Exception as exc:
|
|
260
|
+
# Backend/network errors are not task failures; preserve them for the
|
|
261
|
+
# caller rather than turning them into a successful empty result.
|
|
262
|
+
raise SubmissionError(
|
|
263
|
+
f"celery could not read result for {execution_id!r}: {exc}",
|
|
264
|
+
backend=self._name,
|
|
265
|
+
) from exc
|
|
266
|
+
|
|
267
|
+
state = map_state(getattr(async_result, "state", None))
|
|
268
|
+
if state is ExecutionState.FAILED:
|
|
269
|
+
return ExecutionResult(
|
|
270
|
+
error=str(value),
|
|
271
|
+
error_type=type(value).__qualname__,
|
|
272
|
+
traceback=getattr(async_result, "traceback", None),
|
|
273
|
+
)
|
|
274
|
+
if state is ExecutionState.CANCELLED:
|
|
275
|
+
return ExecutionResult.cancelled()
|
|
276
|
+
return ExecutionResult(value=value)
|
|
277
|
+
|
|
237
278
|
def _cancel(self, execution_id: ExecutionId) -> Execution:
|
|
238
279
|
async_result = self._result_handle(execution_id)
|
|
239
280
|
try:
|
|
@@ -58,10 +58,12 @@ def execute_message(
|
|
|
58
58
|
message: TaskferryMessage,
|
|
59
59
|
*,
|
|
60
60
|
registry: FunctionRegistry | None = None,
|
|
61
|
+
attempt: int | None = None,
|
|
62
|
+
worker_id: str | None = None,
|
|
61
63
|
) -> Any:
|
|
62
64
|
"""Resolve and run one Taskferry message. Pure of Celery, so unit-testable."""
|
|
63
65
|
check_version(message)
|
|
64
|
-
return execute_envelope(message, registry=registry)
|
|
66
|
+
return execute_envelope(message, registry=registry, attempt=attempt, worker_id=worker_id)
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
def register_dispatcher(
|
|
@@ -97,10 +99,16 @@ def register_dispatcher(
|
|
|
97
99
|
@app.task(name=name, **task_options) # type: ignore[untyped-decorator]
|
|
98
100
|
def _taskferry_dispatch(self: Any, message: TaskferryMessage) -> Any:
|
|
99
101
|
policy = decode_retry(message)
|
|
102
|
+
request = getattr(self, "request", None)
|
|
103
|
+
attempt = int(getattr(request, "retries", 0) or 0) + 1
|
|
100
104
|
try:
|
|
101
|
-
return execute_message(
|
|
105
|
+
return execute_message(
|
|
106
|
+
message,
|
|
107
|
+
registry=registry,
|
|
108
|
+
attempt=attempt,
|
|
109
|
+
worker_id=getattr(request, "hostname", None),
|
|
110
|
+
)
|
|
102
111
|
except Exception as exc:
|
|
103
|
-
attempt = int(getattr(getattr(self, "request", None), "retries", 0) or 0) + 1
|
|
104
112
|
if policy.should_retry(exc, attempt):
|
|
105
113
|
# Celery owns the retry — a real re-queue with a real countdown —
|
|
106
114
|
# rather than this function looping and holding a worker slot.
|
taskferry_celery-0.1.0/PKG-INFO
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: taskferry-celery
|
|
3
|
-
Version: 0.1.0
|
|
4
|
-
Summary: Celery task backend for Taskferry — enqueue Taskferry tasks onto a Celery app.
|
|
5
|
-
Project-URL: Homepage, https://github.com/xiidigital/taskferry
|
|
6
|
-
Project-URL: Documentation, https://taskferry.dev
|
|
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: celery,queue,taskferry,tasks
|
|
12
|
-
Classifier: Development Status :: 3 - Alpha
|
|
13
|
-
Classifier: Intended Audience :: Developers
|
|
14
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
-
Classifier: Typing :: Typed
|
|
19
|
-
Requires-Python: >=3.12
|
|
20
|
-
Requires-Dist: taskferry<0.3,>=0.2
|
|
21
|
-
Provides-Extra: celery
|
|
22
|
-
Requires-Dist: celery>=5.3; extra == 'celery'
|
|
23
|
-
Description-Content-Type: text/markdown
|
|
24
|
-
|
|
25
|
-
# taskferry-celery
|
|
26
|
-
|
|
27
|
-
A **Celery** task backend for [Taskferry](https://taskferry.dev). Enqueue Taskferry
|
|
28
|
-
tasks onto a Celery app you already run; Taskferry supplies no worker and
|
|
29
|
-
reimplements none of Celery.
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip install taskferry-celery[celery]
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Submitting
|
|
36
|
-
|
|
37
|
-
```python
|
|
38
|
-
from taskferry import Taskferry
|
|
39
|
-
|
|
40
|
-
runtime = Taskferry.from_mapping(
|
|
41
|
-
{
|
|
42
|
-
"backends": {"cel": {"factory": "celery", "app": "myapp.celery:app"}},
|
|
43
|
-
"defaults": {"task": "cel"},
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
runtime.tasks.submit("myapp.tasks:refresh", 42, queue="metadata")
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Executing (worker)
|
|
50
|
-
|
|
51
|
-
Register the dispatcher once, then run Celery's own worker:
|
|
52
|
-
|
|
53
|
-
```python
|
|
54
|
-
from celery import Celery
|
|
55
|
-
from taskferry_celery import register_dispatcher
|
|
56
|
-
from taskferry.functions import FunctionRegistry
|
|
57
|
-
|
|
58
|
-
app = Celery("myapp", broker="redis://localhost:6379/0")
|
|
59
|
-
register_dispatcher(app, registry=FunctionRegistry(allowed_modules=["myapp"]))
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
celery -A myapp worker
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Capabilities (honest)
|
|
67
|
-
|
|
68
|
-
| Advertised | Not advertised | Why not |
|
|
69
|
-
| --- | --- | --- |
|
|
70
|
-
| submit, state, cancel, delay, priority, retry | `result` | needs a configured result backend Taskferry can't see |
|
|
71
|
-
| | `deduplication` | Celery has no native mechanism — an `idempotency_key` is rejected, not ignored |
|
|
72
|
-
|
|
73
|
-
Retries are the **engine's**: the dispatcher raises Celery's own `self.retry`, so
|
|
74
|
-
a failed task is genuinely re-queued with the requested countdown. Taskferry never
|
|
75
|
-
loops in-process pretending to retry.
|
|
76
|
-
|
|
77
|
-
`state` maps Celery's `PENDING/STARTED/SUCCESS/FAILURE/RETRY/REVOKED` onto the
|
|
78
|
-
portable states. Note Celery reports `PENDING` for both a queued task and an
|
|
79
|
-
unknown id; without a result backend the two are indistinguishable, and this
|
|
80
|
-
adapter says so rather than guessing.
|
|
81
|
-
|
|
82
|
-
Only JSON-safe arguments and a `"module:function"` name cross the wire — never a
|
|
83
|
-
pickled callable.
|
|
84
|
-
|
|
85
|
-
## License
|
|
86
|
-
|
|
87
|
-
Apache-2.0.
|
taskferry_celery-0.1.0/README.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# taskferry-celery
|
|
2
|
-
|
|
3
|
-
A **Celery** task backend for [Taskferry](https://taskferry.dev). Enqueue Taskferry
|
|
4
|
-
tasks onto a Celery app you already run; Taskferry supplies no worker and
|
|
5
|
-
reimplements none of Celery.
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install taskferry-celery[celery]
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Submitting
|
|
12
|
-
|
|
13
|
-
```python
|
|
14
|
-
from taskferry import Taskferry
|
|
15
|
-
|
|
16
|
-
runtime = Taskferry.from_mapping(
|
|
17
|
-
{
|
|
18
|
-
"backends": {"cel": {"factory": "celery", "app": "myapp.celery:app"}},
|
|
19
|
-
"defaults": {"task": "cel"},
|
|
20
|
-
}
|
|
21
|
-
)
|
|
22
|
-
runtime.tasks.submit("myapp.tasks:refresh", 42, queue="metadata")
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Executing (worker)
|
|
26
|
-
|
|
27
|
-
Register the dispatcher once, then run Celery's own worker:
|
|
28
|
-
|
|
29
|
-
```python
|
|
30
|
-
from celery import Celery
|
|
31
|
-
from taskferry_celery import register_dispatcher
|
|
32
|
-
from taskferry.functions import FunctionRegistry
|
|
33
|
-
|
|
34
|
-
app = Celery("myapp", broker="redis://localhost:6379/0")
|
|
35
|
-
register_dispatcher(app, registry=FunctionRegistry(allowed_modules=["myapp"]))
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
celery -A myapp worker
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Capabilities (honest)
|
|
43
|
-
|
|
44
|
-
| Advertised | Not advertised | Why not |
|
|
45
|
-
| --- | --- | --- |
|
|
46
|
-
| submit, state, cancel, delay, priority, retry | `result` | needs a configured result backend Taskferry can't see |
|
|
47
|
-
| | `deduplication` | Celery has no native mechanism — an `idempotency_key` is rejected, not ignored |
|
|
48
|
-
|
|
49
|
-
Retries are the **engine's**: the dispatcher raises Celery's own `self.retry`, so
|
|
50
|
-
a failed task is genuinely re-queued with the requested countdown. Taskferry never
|
|
51
|
-
loops in-process pretending to retry.
|
|
52
|
-
|
|
53
|
-
`state` maps Celery's `PENDING/STARTED/SUCCESS/FAILURE/RETRY/REVOKED` onto the
|
|
54
|
-
portable states. Note Celery reports `PENDING` for both a queued task and an
|
|
55
|
-
unknown id; without a result backend the two are indistinguishable, and this
|
|
56
|
-
adapter says so rather than guessing.
|
|
57
|
-
|
|
58
|
-
Only JSON-safe arguments and a `"module:function"` name cross the wire — never a
|
|
59
|
-
pickled callable.
|
|
60
|
-
|
|
61
|
-
## License
|
|
62
|
-
|
|
63
|
-
Apache-2.0.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|