taskferry-cloudtasks 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_cloudtasks-0.3.1/CHANGELOG.md +38 -0
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/PKG-INFO +16 -3
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/README.md +15 -2
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/pyproject.toml +1 -1
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/src/taskferry_cloudtasks/__init__.py +1 -1
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/src/taskferry_cloudtasks/backend.py +35 -5
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/src/taskferry_cloudtasks/receiver.py +21 -5
- taskferry_cloudtasks-0.3.0/CHANGELOG.md +0 -21
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/.gitignore +0 -0
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/LICENSE +0 -0
- {taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/src/taskferry_cloudtasks/py.typed +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `taskferry-cloudtasks` 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
|
+
- `ATTEMPT_COUNT` through `get_task()` while Cloud Tasks retains the task, and
|
|
14
|
+
`DELETE_PENDING` through `delete_task()` for scheduled or dispatched tasks.
|
|
15
|
+
- Current attempt propagation from Cloud Tasks retry headers into execution
|
|
16
|
+
context.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Keep `STATE`, `RESULT`, and `CANCEL` unadvertised; attempt inspection and
|
|
21
|
+
pending-task deletion do not provide those semantics.
|
|
22
|
+
- Align `taskferry_cloudtasks.__version__` with the distribution version `0.3.1`.
|
|
23
|
+
|
|
24
|
+
## [0.3.0] — 2026-09-19
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- **Native async submit** via `CloudTasksAsyncClient`. `asubmit` creates the task
|
|
29
|
+
through the async client (injected, or built from the existing `gcp` extra),
|
|
30
|
+
skipping the worker thread, and falls back to the thread path when the SDK is
|
|
31
|
+
absent. No new dependency — the async client ships with `google-cloud-tasks`.
|
|
32
|
+
|
|
33
|
+
## [0.2.0] — 2026-07-26
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- Initial release of the Google Cloud Tasks backend, implementing Taskferry's
|
|
38
|
+
framework-independent `TaskBackend` contract.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: taskferry-cloudtasks
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Google Cloud Tasks backend for Taskferry — push-based serverless tasks.
|
|
5
5
|
Project-URL: Homepage, https://github.com/xiidigital/taskferry
|
|
6
6
|
Project-URL: Documentation, https://taskferry.dev
|
|
@@ -110,10 +110,23 @@ that is what makes it portable, and it is why this part is yours.
|
|
|
110
110
|
| ---------- | :-------: | --- |
|
|
111
111
|
| `SUBMIT` · `DELAY` · `RETRY` | yes | `create_task`, `schedule_time`, queue retry config |
|
|
112
112
|
| `DEDUPLICATION` | yes | task names are unique per queue for a bounded window |
|
|
113
|
-
| `
|
|
113
|
+
| `EXECUTION_CONTEXT` | yes | The push request includes the task identity and retry count |
|
|
114
|
+
| `ATTEMPT_COUNT` | yes, while retained | `get_task()` reports `dispatch_count` for an existing task |
|
|
115
|
+
| `DELETE_PENDING` | yes | `delete_task()` removes a scheduled or dispatched delivery |
|
|
116
|
+
| `STATE` · `RESULT` · `CANCEL` | **no** | No durable outcome store, return value, or guaranteed interruption |
|
|
114
117
|
|
|
115
118
|
A handle refuses `status()` here instead of returning a plausible `UNKNOWN`
|
|
116
|
-
forever.
|
|
119
|
+
forever. `handle.attempt_count()` is a separate, temporary query: Cloud Tasks
|
|
120
|
+
returns `dispatch_count` only while the task exists. Successfully completed or
|
|
121
|
+
exhausted tasks are deleted, so this is neither durable state nor a result.
|
|
122
|
+
`handle.delete_pending()` calls Cloud Tasks `delete_task`; it removes a scheduled
|
|
123
|
+
or dispatched task, but it cannot promise to stop a handler that has already
|
|
124
|
+
started. This is deliberately distinct from `cancel()`.
|
|
125
|
+
|
|
126
|
+
The push request's `X-CloudTasks-TaskRetryCount` header is passed through as the
|
|
127
|
+
current Django `TaskContext.attempt` (`retry count + 1`). Cloud Tasks does not
|
|
128
|
+
provide a worker id or the original enqueue timestamp to this adapter. Record
|
|
129
|
+
durable progress, return values, or retry history in application-owned storage.
|
|
117
130
|
|
|
118
131
|
## License
|
|
119
132
|
|
|
@@ -86,10 +86,23 @@ that is what makes it portable, and it is why this part is yours.
|
|
|
86
86
|
| ---------- | :-------: | --- |
|
|
87
87
|
| `SUBMIT` · `DELAY` · `RETRY` | yes | `create_task`, `schedule_time`, queue retry config |
|
|
88
88
|
| `DEDUPLICATION` | yes | task names are unique per queue for a bounded window |
|
|
89
|
-
| `
|
|
89
|
+
| `EXECUTION_CONTEXT` | yes | The push request includes the task identity and retry count |
|
|
90
|
+
| `ATTEMPT_COUNT` | yes, while retained | `get_task()` reports `dispatch_count` for an existing task |
|
|
91
|
+
| `DELETE_PENDING` | yes | `delete_task()` removes a scheduled or dispatched delivery |
|
|
92
|
+
| `STATE` · `RESULT` · `CANCEL` | **no** | No durable outcome store, return value, or guaranteed interruption |
|
|
90
93
|
|
|
91
94
|
A handle refuses `status()` here instead of returning a plausible `UNKNOWN`
|
|
92
|
-
forever.
|
|
95
|
+
forever. `handle.attempt_count()` is a separate, temporary query: Cloud Tasks
|
|
96
|
+
returns `dispatch_count` only while the task exists. Successfully completed or
|
|
97
|
+
exhausted tasks are deleted, so this is neither durable state nor a result.
|
|
98
|
+
`handle.delete_pending()` calls Cloud Tasks `delete_task`; it removes a scheduled
|
|
99
|
+
or dispatched task, but it cannot promise to stop a handler that has already
|
|
100
|
+
started. This is deliberately distinct from `cancel()`.
|
|
101
|
+
|
|
102
|
+
The push request's `X-CloudTasks-TaskRetryCount` header is passed through as the
|
|
103
|
+
current Django `TaskContext.attempt` (`retry count + 1`). Cloud Tasks does not
|
|
104
|
+
provide a worker id or the original enqueue timestamp to this adapter. Record
|
|
105
|
+
durable progress, return values, or retry history in application-owned storage.
|
|
93
106
|
|
|
94
107
|
## License
|
|
95
108
|
|
{taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/src/taskferry_cloudtasks/__init__.py
RENAMED
|
@@ -42,7 +42,7 @@ from __future__ import annotations
|
|
|
42
42
|
from .backend import CLOUD_TASKS_CAPABILITIES, CloudTasksBackend, make_backend
|
|
43
43
|
from .receiver import handle_request, parse_request
|
|
44
44
|
|
|
45
|
-
__version__ = "0.
|
|
45
|
+
__version__ = "0.3.1"
|
|
46
46
|
|
|
47
47
|
__all__ = [
|
|
48
48
|
"CLOUD_TASKS_CAPABILITIES",
|
{taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/src/taskferry_cloudtasks/backend.py
RENAMED
|
@@ -7,9 +7,11 @@ Advertised: ``SUBMIT``, ``DELAY`` (``schedule_time``), ``RETRY`` (the queue's ow
|
|
|
7
7
|
retry configuration), ``DEDUPLICATION`` (a task *name* is unique per queue, which
|
|
8
8
|
is real deduplication with a documented window).
|
|
9
9
|
|
|
10
|
-
Not advertised: ``STATE``
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Not advertised: ``STATE``, ``RESULT`` or ``CANCEL``. Cloud Tasks retains a task
|
|
11
|
+
while it is scheduled or retrying, so the adapter separately exposes its
|
|
12
|
+
``dispatch_count`` and can delete the pending task resource. Those operations do
|
|
13
|
+
not provide durable lifecycle state, a return value, or guaranteed interruption
|
|
14
|
+
of an already-running handler. A handle from this backend therefore raises
|
|
13
15
|
:class:`~taskferry.errors.UnsupportedCapability` on ``status()`` rather than
|
|
14
16
|
returning a plausible-looking ``UNKNOWN`` forever, and an application that needs
|
|
15
17
|
to know whether the work happened records that itself, in its own database, where
|
|
@@ -36,6 +38,7 @@ from taskferry.envelope import ENVELOPE_VERSION, Envelope, build_envelope
|
|
|
36
38
|
from taskferry.errors import ConfigurationError, SubmissionError
|
|
37
39
|
from taskferry.execution import (
|
|
38
40
|
Execution,
|
|
41
|
+
ExecutionId,
|
|
39
42
|
ExecutionKind,
|
|
40
43
|
ExecutionState,
|
|
41
44
|
new_execution_id,
|
|
@@ -52,6 +55,9 @@ CLOUD_TASKS_CAPABILITIES = frozenset(
|
|
|
52
55
|
Capability.DELAY,
|
|
53
56
|
Capability.RETRY,
|
|
54
57
|
Capability.DEDUPLICATION,
|
|
58
|
+
Capability.EXECUTION_CONTEXT,
|
|
59
|
+
Capability.ATTEMPT_COUNT,
|
|
60
|
+
Capability.DELETE_PENDING,
|
|
55
61
|
}
|
|
56
62
|
)
|
|
57
63
|
|
|
@@ -115,6 +121,7 @@ class CloudTasksBackend(BaseBackend):
|
|
|
115
121
|
self._client = client
|
|
116
122
|
self._async_client = async_client
|
|
117
123
|
self._name = name
|
|
124
|
+
self._provider_ids: dict[str, str] = {}
|
|
118
125
|
|
|
119
126
|
@property
|
|
120
127
|
def name(self) -> str:
|
|
@@ -192,8 +199,8 @@ class CloudTasksBackend(BaseBackend):
|
|
|
192
199
|
self, spec: TaskSpec, created: Any, queue_path: str, queue: str
|
|
193
200
|
) -> Execution:
|
|
194
201
|
external_id = getattr(created, "name", None)
|
|
195
|
-
|
|
196
|
-
id=new_execution_id(ExecutionKind.TASK),
|
|
202
|
+
execution = Execution(
|
|
203
|
+
id=spec.execution_id or new_execution_id(ExecutionKind.TASK),
|
|
197
204
|
kind=ExecutionKind.TASK,
|
|
198
205
|
backend=self._name,
|
|
199
206
|
# QUEUED is the last thing this backend can honestly observe: Cloud
|
|
@@ -212,6 +219,9 @@ class CloudTasksBackend(BaseBackend):
|
|
|
212
219
|
),
|
|
213
220
|
metadata={"queue": queue, "url": self._url},
|
|
214
221
|
)
|
|
222
|
+
if external_id:
|
|
223
|
+
self._provider_ids[str(execution.id)] = str(external_id)
|
|
224
|
+
return execution
|
|
215
225
|
|
|
216
226
|
def _submit(self, spec: ExecutionSpec) -> Execution:
|
|
217
227
|
assert isinstance(spec, TaskSpec)
|
|
@@ -265,6 +275,26 @@ class CloudTasksBackend(BaseBackend):
|
|
|
265
275
|
self.hooks.after_submit(spec, execution)
|
|
266
276
|
return execution
|
|
267
277
|
|
|
278
|
+
def _task_name(self, execution_id: ExecutionId) -> str:
|
|
279
|
+
value = str(execution_id)
|
|
280
|
+
return self._provider_ids.get(value, value)
|
|
281
|
+
|
|
282
|
+
def _attempt_count(self, execution_id: ExecutionId) -> int:
|
|
283
|
+
"""Return Cloud Tasks dispatch_count while the task is retained by Google."""
|
|
284
|
+
task = self._tasks().get_task(request={"name": self._task_name(execution_id)})
|
|
285
|
+
count = (
|
|
286
|
+
task.get("dispatch_count")
|
|
287
|
+
if isinstance(task, dict)
|
|
288
|
+
else getattr(task, "dispatch_count", None)
|
|
289
|
+
)
|
|
290
|
+
if count is None:
|
|
291
|
+
raise RuntimeError("Cloud Tasks get_task response did not include dispatch_count")
|
|
292
|
+
return int(count)
|
|
293
|
+
|
|
294
|
+
def _delete_pending(self, execution_id: ExecutionId) -> None:
|
|
295
|
+
"""Delete a scheduled or dispatched task; an active handler may continue."""
|
|
296
|
+
self._tasks().delete_task(request={"name": self._task_name(execution_id)})
|
|
297
|
+
|
|
268
298
|
@staticmethod
|
|
269
299
|
def _correlation_headers(correlation: Correlation | None) -> dict[str, str]:
|
|
270
300
|
"""Propagate correlation and trace context as HTTP headers.
|
{taskferry_cloudtasks-0.3.0 → taskferry_cloudtasks-0.3.1}/src/taskferry_cloudtasks/receiver.py
RENAMED
|
@@ -53,11 +53,14 @@ from __future__ import annotations
|
|
|
53
53
|
|
|
54
54
|
import json
|
|
55
55
|
from collections.abc import Mapping
|
|
56
|
+
from datetime import UTC, datetime
|
|
56
57
|
from typing import Any
|
|
57
58
|
|
|
58
59
|
from taskferry.core.correlation import Correlation, use_correlation
|
|
59
60
|
from taskferry.envelope import read_envelope
|
|
60
61
|
from taskferry.errors import SerializationError
|
|
62
|
+
from taskferry.execution import ExecutionId
|
|
63
|
+
from taskferry.execution_context import TaskExecutionContext, use_task_execution
|
|
61
64
|
from taskferry.functions import FunctionRegistry, is_async_callable
|
|
62
65
|
|
|
63
66
|
from .backend import CloudTasksMessage
|
|
@@ -106,11 +109,24 @@ def handle_request(
|
|
|
106
109
|
kwargs = dict(message.get("kwargs") or {})
|
|
107
110
|
|
|
108
111
|
with use_correlation(_correlation_from(message, headers)):
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
normalized_headers = {key.lower(): value for key, value in (headers or {}).items()}
|
|
113
|
+
retry_count = normalized_headers.get("x-cloudtasks-taskretrycount")
|
|
114
|
+
attempt = None if retry_count is None else int(retry_count) + 1
|
|
115
|
+
execution_context = TaskExecutionContext(
|
|
116
|
+
execution_id=(
|
|
117
|
+
None
|
|
118
|
+
if not message.get("execution_id")
|
|
119
|
+
else ExecutionId(str(message["execution_id"]))
|
|
120
|
+
),
|
|
121
|
+
attempt=attempt,
|
|
122
|
+
started_at=datetime.now(UTC),
|
|
123
|
+
)
|
|
124
|
+
with use_task_execution(execution_context):
|
|
125
|
+
if is_async_callable(func):
|
|
126
|
+
import asyncio
|
|
127
|
+
|
|
128
|
+
return asyncio.run(func(*args, **kwargs))
|
|
129
|
+
return func(*args, **kwargs)
|
|
114
130
|
|
|
115
131
|
|
|
116
132
|
def _correlation_from(message: CloudTasksMessage, headers: Mapping[str, str] | None) -> Correlation:
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to `taskferry-cloudtasks` 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.3.0] — 2026-09-19
|
|
8
|
-
|
|
9
|
-
### Added
|
|
10
|
-
|
|
11
|
-
- **Native async submit** via `CloudTasksAsyncClient`. `asubmit` creates the task
|
|
12
|
-
through the async client (injected, or built from the existing `gcp` extra),
|
|
13
|
-
skipping the worker thread, and falls back to the thread path when the SDK is
|
|
14
|
-
absent. No new dependency — the async client ships with `google-cloud-tasks`.
|
|
15
|
-
|
|
16
|
-
## [0.2.0] — 2026-07-26
|
|
17
|
-
|
|
18
|
-
### Added
|
|
19
|
-
|
|
20
|
-
- Initial release, extracted from the Django-coupled backends of `taskferry-django` 0.1
|
|
21
|
-
and rebuilt against the framework-agnostic Taskferry ports.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|