durable-workflow 2.0.1__tar.gz → 2.0.3__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.
- {durable_workflow-2.0.1/src/durable_workflow.egg-info → durable_workflow-2.0.3}/PKG-INFO +1 -1
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/pyproject.toml +3 -3
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/__init__.py +2 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/client.py +6 -2
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/errors.py +37 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/retry_policy.py +63 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/worker.py +62 -8
- {durable_workflow-2.0.1 → durable_workflow-2.0.3/src/durable_workflow.egg-info}/PKG-INFO +1 -1
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow.egg-info/SOURCES.txt +2 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_pypi_project_surface.py +2 -3
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_release_metadata.py +2 -2
- durable_workflow-2.0.3/tests/test_storage_admission.py +590 -0
- durable_workflow-2.0.3/tests/test_workflow_result_timeout.py +61 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/LICENSE +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/README.md +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/setup.cfg +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/_avro.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/activity.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/auth_composition.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/external_storage.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/external_task_input.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/external_task_result.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/history_bundle_verify.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/interceptors.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/invocable.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/metrics.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/nexus.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/py.typed +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/python_conformance.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/replay_conformance.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/replay_verify.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/serializer.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/sync.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/testing.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/workflow.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow/workflow_updates_conformance.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow.egg-info/dependency_links.txt +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow.egg-info/entry_points.txt +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow.egg-info/requires.txt +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/src/durable_workflow.egg-info/top_level.txt +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_activity_context.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_auth_composition.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_avro_value_benchmark.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_avro_value_protocol.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_ci_checkout.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_ci_integration_endpoint.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_client.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_codec_regression_corpus.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_control_plane_parity_fixtures.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_docstring_cross_references.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_durable_selection.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_errors.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_external_storage.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_external_task_input.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_external_task_result.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_golden_history_replay.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_history_bundle_verify.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_history_event_contract.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_invocable.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_message_streams.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_metrics.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_order_processing_example.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_parallel_completion_order_replay.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_parallel_saga_authoring.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_public_boundary_scanner.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_python_conformance.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_queries.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_readme_quickstart.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_replay.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_replay_conformance.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_replay_regression_corpus.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_replay_verify.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_retry_policy.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_runtime_external_payload_transport.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_schedules.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_serializer.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_signals.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_sleep.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_standalone_activity_client.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_sync.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_testing_harness.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_update_signal_condition_replay.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_updates.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_wait_condition.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_worker.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_workflow_streams.py +0 -0
- {durable_workflow-2.0.1 → durable_workflow-2.0.3}/tests/test_workflow_updates_conformance.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "durable-workflow"
|
|
7
|
-
version = "2.0.
|
|
7
|
+
version = "2.0.3"
|
|
8
8
|
description = "Python client and worker SDK for Durable Workflow Cloud and self-hosted Server"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -71,8 +71,8 @@ durable-workflow-replay-conformance = "durable_workflow.replay_conformance:main"
|
|
|
71
71
|
durable-workflow-workflow-updates-conformance = "durable_workflow.workflow_updates_conformance:main"
|
|
72
72
|
|
|
73
73
|
[tool.durable-workflow]
|
|
74
|
-
product-train = "2.0.
|
|
75
|
-
registry-version = "2.0.
|
|
74
|
+
product-train = "2.0.3"
|
|
75
|
+
registry-version = "2.0.3"
|
|
76
76
|
supported-server-versions = "2.0.0"
|
|
77
77
|
worker-protocol-version = "1.19"
|
|
78
78
|
control-plane-version = "2"
|
|
@@ -95,6 +95,7 @@ from .errors import (
|
|
|
95
95
|
WorkflowNotFound,
|
|
96
96
|
WorkflowPayloadDecodeError,
|
|
97
97
|
WorkflowTerminated,
|
|
98
|
+
WorkflowTimedOut,
|
|
98
99
|
)
|
|
99
100
|
from .external_storage import (
|
|
100
101
|
EXTERNAL_PAYLOAD_REFERENCE_SCHEMA,
|
|
@@ -374,6 +375,7 @@ __all__ = [
|
|
|
374
375
|
"WorkflowFailed",
|
|
375
376
|
"WorkflowNotFound",
|
|
376
377
|
"WorkflowTerminated",
|
|
378
|
+
"WorkflowTimedOut",
|
|
377
379
|
"EXTERNAL_TASK_INPUT_CONTRACT_SCHEMA",
|
|
378
380
|
"EXTERNAL_TASK_INPUT_MEDIA_TYPE",
|
|
379
381
|
"EXTERNAL_TASK_INPUT_SCHEMA",
|
|
@@ -46,6 +46,7 @@ from .errors import (
|
|
|
46
46
|
WorkflowCancelled,
|
|
47
47
|
WorkflowFailed,
|
|
48
48
|
WorkflowTerminated,
|
|
49
|
+
WorkflowTimedOut,
|
|
49
50
|
_raise_for_status,
|
|
50
51
|
)
|
|
51
52
|
from .external_storage import (
|
|
@@ -4141,8 +4142,9 @@ class Client:
|
|
|
4141
4142
|
Raises :class:`~durable_workflow.errors.WorkflowFailed`,
|
|
4142
4143
|
:class:`~durable_workflow.errors.WorkflowCancelled`, or
|
|
4143
4144
|
:class:`~durable_workflow.errors.WorkflowTerminated` if the workflow
|
|
4144
|
-
ended in a non-success state
|
|
4145
|
-
|
|
4145
|
+
ended in a non-success state. A persisted execution or run deadline
|
|
4146
|
+
raises :class:`~durable_workflow.errors.WorkflowTimedOut`; a caller's
|
|
4147
|
+
:class:`TimeoutError` means ``timeout`` seconds elapsed while waiting.
|
|
4146
4148
|
"""
|
|
4147
4149
|
deadline = asyncio.get_running_loop().time() + timeout
|
|
4148
4150
|
while True:
|
|
@@ -4177,6 +4179,8 @@ class Client:
|
|
|
4177
4179
|
raise WorkflowCancelled(
|
|
4178
4180
|
payload.get("reason", "workflow was cancelled")
|
|
4179
4181
|
)
|
|
4182
|
+
if etype == "WorkflowTimedOut":
|
|
4183
|
+
raise WorkflowTimedOut()
|
|
4180
4184
|
return None
|
|
4181
4185
|
if asyncio.get_running_loop().time() > deadline:
|
|
4182
4186
|
raise TimeoutError(
|
|
@@ -171,6 +171,32 @@ class ServerError(DurableWorkflowError):
|
|
|
171
171
|
return self.body.get("reason")
|
|
172
172
|
return None
|
|
173
173
|
|
|
174
|
+
def is_storage_admission_failure(self, poll_request_id: str | None = None) -> bool:
|
|
175
|
+
"""Whether the runtime explicitly refused admission and requested an identity-preserving retry."""
|
|
176
|
+
body = self.body
|
|
177
|
+
if (
|
|
178
|
+
self.status != 503
|
|
179
|
+
or not isinstance(body, dict)
|
|
180
|
+
or self.reason() not in ("storage_pressure", "storage_admission_unavailable")
|
|
181
|
+
or body.get("retryable") is not True
|
|
182
|
+
or type(body.get("retry_after_seconds")) is not int
|
|
183
|
+
or body["retry_after_seconds"] <= 0
|
|
184
|
+
or body.get("storage_state") not in ("draining", "fenced")
|
|
185
|
+
or (self.reason() == "storage_admission_unavailable" and body["storage_state"] != "fenced")
|
|
186
|
+
or ("request_admitted" in body and body["request_admitted"] is not False)
|
|
187
|
+
):
|
|
188
|
+
return False
|
|
189
|
+
if poll_request_id is None:
|
|
190
|
+
return body.get("request_admitted") is False
|
|
191
|
+
return (
|
|
192
|
+
bool(poll_request_id)
|
|
193
|
+
and "task" in body and body["task"] is None
|
|
194
|
+
and body.get("poll_status") == self.reason()
|
|
195
|
+
and body.get("poll_request_id") == poll_request_id
|
|
196
|
+
and body.get("retry_same_poll_request_id") is True
|
|
197
|
+
and body.get("claim_admitted") is False
|
|
198
|
+
)
|
|
199
|
+
|
|
174
200
|
|
|
175
201
|
class NexusOperationFailed(DurableWorkflowError):
|
|
176
202
|
"""A Nexus service operation completed with a typed service failure."""
|
|
@@ -560,6 +586,17 @@ class WorkflowTerminated(DurableWorkflowError):
|
|
|
560
586
|
super().__init__(message)
|
|
561
587
|
|
|
562
588
|
|
|
589
|
+
class WorkflowTimedOut(DurableWorkflowError):
|
|
590
|
+
"""A persisted workflow execution or run deadline expired.
|
|
591
|
+
|
|
592
|
+
Unlike a caller's :class:`TimeoutError` while polling, this is a terminal
|
|
593
|
+
workflow outcome recorded by the runtime.
|
|
594
|
+
"""
|
|
595
|
+
|
|
596
|
+
def __init__(self, message: str = "workflow execution timed out") -> None:
|
|
597
|
+
super().__init__(message)
|
|
598
|
+
|
|
599
|
+
|
|
563
600
|
class SagaCompensationFailed(DurableWorkflowError):
|
|
564
601
|
"""A saga compensation failed after an earlier workflow failure.
|
|
565
602
|
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
15
|
import asyncio
|
|
16
|
+
import contextvars
|
|
17
|
+
import json
|
|
18
|
+
import logging
|
|
16
19
|
import random
|
|
17
20
|
from collections.abc import Awaitable, Callable
|
|
18
21
|
from dataclasses import dataclass
|
|
@@ -20,7 +23,40 @@ from typing import TypeVar
|
|
|
20
23
|
|
|
21
24
|
import httpx
|
|
22
25
|
|
|
26
|
+
from .errors import ServerError
|
|
27
|
+
|
|
23
28
|
T = TypeVar("T")
|
|
29
|
+
log = logging.getLogger("durable_workflow.worker")
|
|
30
|
+
|
|
31
|
+
# Task-local so sharing a Client never changes unrelated client/control requests.
|
|
32
|
+
_worker_storage_admission_stop: contextvars.ContextVar[Callable[[], bool] | None] = contextvars.ContextVar(
|
|
33
|
+
"worker_storage_admission_stop", default=None,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _storage_refusal(exc: Exception) -> tuple[ServerError, str | None] | None:
|
|
38
|
+
if not isinstance(exc, httpx.HTTPStatusError):
|
|
39
|
+
return None
|
|
40
|
+
if "X-Durable-Workflow-Protocol-Version" not in exc.request.headers:
|
|
41
|
+
return None
|
|
42
|
+
try:
|
|
43
|
+
body = exc.response.json()
|
|
44
|
+
except ValueError:
|
|
45
|
+
return None
|
|
46
|
+
error = ServerError(exc.response.status_code, body)
|
|
47
|
+
if error.reason() not in ("storage_pressure", "storage_admission_unavailable"):
|
|
48
|
+
return None
|
|
49
|
+
poll_id = None
|
|
50
|
+
if exc.request.url.path.endswith("/poll"):
|
|
51
|
+
try:
|
|
52
|
+
request = json.loads(exc.request.content)
|
|
53
|
+
poll_id = request.get("poll_request_id") if isinstance(request, dict) else None
|
|
54
|
+
except ValueError:
|
|
55
|
+
pass
|
|
56
|
+
# An invalid submitted ID must not fall through to the non-poll contract.
|
|
57
|
+
if not isinstance(poll_id, str) or not poll_id:
|
|
58
|
+
poll_id = ""
|
|
59
|
+
return error, poll_id
|
|
24
60
|
|
|
25
61
|
|
|
26
62
|
@dataclass
|
|
@@ -81,6 +117,7 @@ class TransportRetryPolicy:
|
|
|
81
117
|
Raises the last exception if all retries are exhausted.
|
|
82
118
|
"""
|
|
83
119
|
attempt = 0
|
|
120
|
+
storage_attempt = 0
|
|
84
121
|
last_exc: Exception | None = None
|
|
85
122
|
|
|
86
123
|
while attempt < self.max_attempts:
|
|
@@ -89,6 +126,32 @@ class TransportRetryPolicy:
|
|
|
89
126
|
return result
|
|
90
127
|
except Exception as exc:
|
|
91
128
|
last_exc = exc
|
|
129
|
+
stop = _worker_storage_admission_stop.get()
|
|
130
|
+
refusal = _storage_refusal(exc) if stop is not None else None
|
|
131
|
+
if refusal is not None and stop is not None:
|
|
132
|
+
error, poll_id = refusal
|
|
133
|
+
if not error.is_storage_admission_failure(poll_id) or stop():
|
|
134
|
+
raise
|
|
135
|
+
storage_attempt += 1
|
|
136
|
+
assert isinstance(error.body, dict)
|
|
137
|
+
delay = min(
|
|
138
|
+
5.0,
|
|
139
|
+
max(
|
|
140
|
+
self.backoff_seconds(min(storage_attempt - 1, 6)),
|
|
141
|
+
error.body["retry_after_seconds"],
|
|
142
|
+
),
|
|
143
|
+
)
|
|
144
|
+
log.warning("storage admission paused; retrying the same worker request in %.2fs", delay)
|
|
145
|
+
# Do not consume the finite transport budget or repeat serialization/uploads.
|
|
146
|
+
while delay > 0:
|
|
147
|
+
if stop():
|
|
148
|
+
raise
|
|
149
|
+
interval = min(0.1, delay)
|
|
150
|
+
await asyncio.sleep(interval)
|
|
151
|
+
delay -= interval
|
|
152
|
+
if stop():
|
|
153
|
+
raise
|
|
154
|
+
continue
|
|
92
155
|
if not self.should_retry(exc, attempt):
|
|
93
156
|
raise
|
|
94
157
|
|
|
@@ -27,10 +27,11 @@ import time
|
|
|
27
27
|
import traceback
|
|
28
28
|
import types
|
|
29
29
|
import uuid
|
|
30
|
-
from collections.abc import Awaitable, Callable, Iterable, Mapping
|
|
30
|
+
from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping
|
|
31
31
|
from datetime import datetime, timezone
|
|
32
|
+
from functools import wraps
|
|
32
33
|
from types import FunctionType
|
|
33
|
-
from typing import Annotated, Any, Literal, Union, get_args, get_origin, get_type_hints
|
|
34
|
+
from typing import Annotated, Any, Concatenate, Literal, ParamSpec, TypeVar, Union, get_args, get_origin, get_type_hints
|
|
34
35
|
|
|
35
36
|
from . import serializer
|
|
36
37
|
from .activity import ActivityContext, ActivityInfo, _set_context
|
|
@@ -75,6 +76,7 @@ from .metrics import (
|
|
|
75
76
|
WORKER_TASKS,
|
|
76
77
|
MetricsRecorder,
|
|
77
78
|
)
|
|
79
|
+
from .retry_policy import _worker_storage_admission_stop
|
|
78
80
|
from .workflow import (
|
|
79
81
|
Command,
|
|
80
82
|
NexusServiceCall,
|
|
@@ -137,6 +139,27 @@ _WORKFLOW_TASK_COMPLETION_MAX_ATTEMPTS = 3
|
|
|
137
139
|
_WORKFLOW_TASK_COMPLETION_RETRY_DELAYS = (0.05, 0.2)
|
|
138
140
|
_WORKFLOW_TASK_NEXUS_RESOLUTION_LIMIT = 100
|
|
139
141
|
_WORKER_WORKFLOW_FINGERPRINTS: dict[tuple[str, str], str] = {}
|
|
142
|
+
_P = ParamSpec("_P")
|
|
143
|
+
_R = TypeVar("_R")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _with_storage_admission_retries(
|
|
147
|
+
fn: Callable[Concatenate[Worker, _P], Coroutine[Any, Any, _R]],
|
|
148
|
+
) -> Callable[Concatenate[Worker, _P], Coroutine[Any, Any, _R]]:
|
|
149
|
+
@wraps(fn)
|
|
150
|
+
async def run(self: Worker, /, *args: _P.args, **kwargs: _P.kwargs) -> _R:
|
|
151
|
+
token = _worker_storage_admission_stop.set(self._stop.is_set)
|
|
152
|
+
try:
|
|
153
|
+
return await fn(self, *args, **kwargs)
|
|
154
|
+
finally:
|
|
155
|
+
_worker_storage_admission_stop.reset(token)
|
|
156
|
+
return run
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _is_storage_admission_error(error: BaseException) -> bool:
|
|
160
|
+
return isinstance(error, ServerError) and error.reason() in (
|
|
161
|
+
"storage_pressure", "storage_admission_unavailable",
|
|
162
|
+
)
|
|
140
163
|
|
|
141
164
|
|
|
142
165
|
def _command_payload_codec(codec: object) -> str:
|
|
@@ -208,6 +231,8 @@ def _should_fail_workflow_task_after_completion_error(error: BaseException) -> b
|
|
|
208
231
|
|
|
209
232
|
|
|
210
233
|
def _should_retry_workflow_task_completion_error(error: BaseException) -> bool:
|
|
234
|
+
if _is_storage_admission_error(error):
|
|
235
|
+
return False
|
|
211
236
|
if isinstance(error, ServerError):
|
|
212
237
|
return error.status >= 500 or error.status == 429
|
|
213
238
|
|
|
@@ -1424,6 +1449,8 @@ class Worker:
|
|
|
1424
1449
|
)
|
|
1425
1450
|
except Exception as e:
|
|
1426
1451
|
log.warning("failed to complete workflow update task %s: %s", task_id, e)
|
|
1452
|
+
if _is_storage_admission_error(e):
|
|
1453
|
+
return None
|
|
1427
1454
|
if _should_fail_workflow_task_after_completion_error(e):
|
|
1428
1455
|
await self._report_workflow_task_after_completion_error(task_id, attempt, e)
|
|
1429
1456
|
return None
|
|
@@ -1550,6 +1577,8 @@ class Worker:
|
|
|
1550
1577
|
)
|
|
1551
1578
|
except Exception as e:
|
|
1552
1579
|
log.warning("failed to complete workflow task %s: %s", task_id, e)
|
|
1580
|
+
if _is_storage_admission_error(e):
|
|
1581
|
+
return None
|
|
1553
1582
|
if _should_fail_workflow_task_after_completion_error(e):
|
|
1554
1583
|
await self._report_workflow_task_after_completion_error(task_id, attempt, e)
|
|
1555
1584
|
return None
|
|
@@ -1736,6 +1765,8 @@ class Worker:
|
|
|
1736
1765
|
log.warning("failed to report activity failure: %s", fe)
|
|
1737
1766
|
return "failed_non_retryable"
|
|
1738
1767
|
except Exception as e:
|
|
1768
|
+
if _is_storage_admission_error(e):
|
|
1769
|
+
raise
|
|
1739
1770
|
log.exception("activity failed")
|
|
1740
1771
|
try:
|
|
1741
1772
|
await self.client.fail_activity_task(
|
|
@@ -1971,6 +2002,9 @@ class Worker:
|
|
|
1971
2002
|
**self._external_storage_completion_kwargs(),
|
|
1972
2003
|
)
|
|
1973
2004
|
except ServerError as e:
|
|
2005
|
+
if _is_storage_admission_error(e):
|
|
2006
|
+
log.warning("query task %s acknowledgement paused: %s", query_task_id, e)
|
|
2007
|
+
return "complete_error"
|
|
1974
2008
|
if _is_final_query_task_rejection(e):
|
|
1975
2009
|
log.info(
|
|
1976
2010
|
"query task %s completion was rejected after the task ended server-side: %s",
|
|
@@ -2147,6 +2181,8 @@ class Worker:
|
|
|
2147
2181
|
self._release_workflow_capacity()
|
|
2148
2182
|
if self._stop.is_set():
|
|
2149
2183
|
return
|
|
2184
|
+
if _is_storage_admission_error(e):
|
|
2185
|
+
raise
|
|
2150
2186
|
self._record_poll_metrics("workflow", "error", time.perf_counter() - poll_start)
|
|
2151
2187
|
log.warning("workflow poll error: %s", e)
|
|
2152
2188
|
await asyncio.sleep(1.0)
|
|
@@ -2236,10 +2272,15 @@ class Worker:
|
|
|
2236
2272
|
timeout=self._poll_http_timeout,
|
|
2237
2273
|
build_id=self.build_id,
|
|
2238
2274
|
)
|
|
2275
|
+
except asyncio.CancelledError:
|
|
2276
|
+
self._act_semaphore.release()
|
|
2277
|
+
raise
|
|
2239
2278
|
except Exception as e:
|
|
2240
2279
|
self._act_semaphore.release()
|
|
2241
2280
|
if self._stop.is_set():
|
|
2242
2281
|
return
|
|
2282
|
+
if _is_storage_admission_error(e):
|
|
2283
|
+
raise
|
|
2243
2284
|
self._record_poll_metrics("activity", "error", time.perf_counter() - poll_start)
|
|
2244
2285
|
log.warning("activity poll error: %s", e)
|
|
2245
2286
|
await asyncio.sleep(1.0)
|
|
@@ -2289,6 +2330,8 @@ class Worker:
|
|
|
2289
2330
|
query_thread_stop is not None and query_thread_stop.is_set()
|
|
2290
2331
|
):
|
|
2291
2332
|
return
|
|
2333
|
+
if _is_storage_admission_error(e):
|
|
2334
|
+
raise
|
|
2292
2335
|
self._record_poll_metrics("query", "error", time.perf_counter() - poll_start)
|
|
2293
2336
|
log.warning("query poll error: %s", e)
|
|
2294
2337
|
await asyncio.sleep(1.0)
|
|
@@ -2525,6 +2568,7 @@ class Worker:
|
|
|
2525
2568
|
except Exception:
|
|
2526
2569
|
log.exception("query task poller thread stopped unexpectedly")
|
|
2527
2570
|
|
|
2571
|
+
@_with_storage_admission_retries
|
|
2528
2572
|
async def _query_task_thread_main(self) -> None:
|
|
2529
2573
|
loop = asyncio.get_running_loop()
|
|
2530
2574
|
task = asyncio.current_task()
|
|
@@ -2562,6 +2606,7 @@ class Worker:
|
|
|
2562
2606
|
"the worker registration remains active"
|
|
2563
2607
|
)
|
|
2564
2608
|
|
|
2609
|
+
@_with_storage_admission_retries
|
|
2565
2610
|
async def run(self) -> None:
|
|
2566
2611
|
"""Register the worker and poll until `stop()` is called or the task is cancelled."""
|
|
2567
2612
|
self._begin_run()
|
|
@@ -2622,6 +2667,8 @@ class Worker:
|
|
|
2622
2667
|
process_metrics=self._current_process_metrics(),
|
|
2623
2668
|
)
|
|
2624
2669
|
except Exception as e:
|
|
2670
|
+
if _is_storage_admission_error(e) and not self._stop.is_set():
|
|
2671
|
+
raise
|
|
2625
2672
|
log.warning("worker heartbeat failed: %s", e)
|
|
2626
2673
|
continue
|
|
2627
2674
|
if isinstance(ack, dict):
|
|
@@ -2703,6 +2750,7 @@ class Worker:
|
|
|
2703
2750
|
|
|
2704
2751
|
return metrics
|
|
2705
2752
|
|
|
2753
|
+
@_with_storage_admission_retries
|
|
2706
2754
|
async def run_until(
|
|
2707
2755
|
self,
|
|
2708
2756
|
*,
|
|
@@ -2714,17 +2762,19 @@ class Worker:
|
|
|
2714
2762
|
|
|
2715
2763
|
This is intended for examples, smoke tests, and single-workflow scripts.
|
|
2716
2764
|
Long-running workers should call :meth:`run` and coordinate shutdown from
|
|
2717
|
-
their process supervisor.
|
|
2765
|
+
their process supervisor. ``timeout`` includes registration and runtime
|
|
2766
|
+
admission pauses; shutdown retains its separate drain timeout.
|
|
2718
2767
|
"""
|
|
2719
2768
|
background_tasks: list[asyncio.Task[Any]] = []
|
|
2769
|
+
deadline = asyncio.get_running_loop().time() + timeout
|
|
2720
2770
|
|
|
2721
2771
|
self._begin_run()
|
|
2722
2772
|
try:
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2773
|
+
try:
|
|
2774
|
+
await asyncio.wait_for(self._register(), timeout=timeout)
|
|
2775
|
+
finally:
|
|
2776
|
+
self._registration_done.set()
|
|
2726
2777
|
|
|
2727
|
-
try:
|
|
2728
2778
|
if self._stop.is_set():
|
|
2729
2779
|
raise asyncio.CancelledError
|
|
2730
2780
|
background_tasks.append(asyncio.create_task(self._heartbeat_loop()))
|
|
@@ -2742,7 +2792,11 @@ class Worker:
|
|
|
2742
2792
|
)
|
|
2743
2793
|
)
|
|
2744
2794
|
self._poller_tasks.add(run_until_loop)
|
|
2745
|
-
return await
|
|
2795
|
+
return await asyncio.wait_for(
|
|
2796
|
+
run_until_loop, timeout=max(0.0, deadline - asyncio.get_running_loop().time()),
|
|
2797
|
+
)
|
|
2798
|
+
except asyncio.TimeoutError as error:
|
|
2799
|
+
raise TimeoutError(f"workflow {workflow_id} not terminal after {timeout}s") from error
|
|
2746
2800
|
finally:
|
|
2747
2801
|
primary_error = sys.exc_info()[1]
|
|
2748
2802
|
primary_traceback = primary_error.__traceback__ if primary_error is not None else None
|
|
@@ -73,11 +73,13 @@ tests/test_serializer.py
|
|
|
73
73
|
tests/test_signals.py
|
|
74
74
|
tests/test_sleep.py
|
|
75
75
|
tests/test_standalone_activity_client.py
|
|
76
|
+
tests/test_storage_admission.py
|
|
76
77
|
tests/test_sync.py
|
|
77
78
|
tests/test_testing_harness.py
|
|
78
79
|
tests/test_update_signal_condition_replay.py
|
|
79
80
|
tests/test_updates.py
|
|
80
81
|
tests/test_wait_condition.py
|
|
81
82
|
tests/test_worker.py
|
|
83
|
+
tests/test_workflow_result_timeout.py
|
|
82
84
|
tests/test_workflow_streams.py
|
|
83
85
|
tests/test_workflow_updates_conformance.py
|
|
@@ -348,7 +348,7 @@ def test_stable_audit_requires_root_and_bare_install(
|
|
|
348
348
|
assert evidence["historical_versions"] == ["0.4.105", "0.4.106"]
|
|
349
349
|
|
|
350
350
|
|
|
351
|
-
def
|
|
351
|
+
def test_stable_root_preserves_historical_files_without_overriding_yanks() -> None:
|
|
352
352
|
source = source_metadata(stable=True)
|
|
353
353
|
exact_urls = verify_exact_version_json(exact_version_payload(source), source)
|
|
354
354
|
|
|
@@ -356,8 +356,7 @@ def test_stable_root_preserves_non_yanked_historical_files() -> None:
|
|
|
356
356
|
|
|
357
357
|
payload = stable_project_payload()
|
|
358
358
|
payload["releases"]["0.4.106"][0]["yanked"] = True
|
|
359
|
-
|
|
360
|
-
verify_stable_project_json(payload, source, exact_urls)
|
|
359
|
+
assert verify_stable_project_json(payload, source, exact_urls) == ("0.4.105", "0.4.106")
|
|
361
360
|
|
|
362
361
|
|
|
363
362
|
def test_prerelease_evidence_records_deferred_default_surface(
|
|
@@ -41,9 +41,9 @@ def test_worker_release_identity_matches_supported_server_and_protocol() -> None
|
|
|
41
41
|
project = manifest["project"]
|
|
42
42
|
release = manifest["tool"]["durable-workflow"]
|
|
43
43
|
|
|
44
|
-
assert project["version"] == "2.0.
|
|
44
|
+
assert project["version"] == "2.0.3"
|
|
45
45
|
assert release["product-train"] == project["version"]
|
|
46
|
-
assert release["registry-version"] == "2.0.
|
|
46
|
+
assert release["registry-version"] == "2.0.3"
|
|
47
47
|
assert release["supported-server-versions"] == "2.0.0"
|
|
48
48
|
assert release["worker-protocol-version"] == PROTOCOL_VERSION == "1.19"
|
|
49
49
|
assert release["durable-selection"] is True
|