requence 0.8.1.dev98__tar.gz → 0.8.2__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.
- {requence-0.8.1.dev98/requence.egg-info → requence-0.8.2}/PKG-INFO +1 -1
- {requence-0.8.1.dev98 → requence-0.8.2}/pyproject.toml +1 -1
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/__init__.py +117 -13
- {requence-0.8.1.dev98 → requence-0.8.2/requence.egg-info}/PKG-INFO +1 -1
- {requence-0.8.1.dev98 → requence-0.8.2}/MANIFEST.in +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/README.md +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/__init__.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/callbacks/__init__.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/callbacks/context.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/callbacks/handler.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/client_properties.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/context.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/exceptions.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/__init__.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/errors.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/handlers/__init__.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/handlers/claim_check_handler.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/handlers/context.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/handlers/file_handler.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/handlers/stream_handler.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/pending_uploads.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/requence_file.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/requence_stream.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/sanitize_log_data.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/stream_framing.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/files/transport.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/internal_types.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/logger.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/obfuscase.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/py.typed +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/reachable.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/requence_callback.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/requence_file.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/requence_stream.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/boundary.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/callback_growth.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/cli.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/durable_callback.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/surface_handler.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/transformer.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/types.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/ui.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/service/ui_watch.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/store.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/__init__.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/abort_task.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/ack_task.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/cli.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/get_task.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/ingress.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/protect_task.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/task.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/task_watcher.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/types.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/updates.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/task/utils.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/__init__.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/context.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/errors.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/guards.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/message_handler.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/transform.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/value_handler.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/transformer/walk.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/utils.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/wire.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence/wire_codec.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence.egg-info/SOURCES.txt +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence.egg-info/dependency_links.txt +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence.egg-info/entry_points.txt +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence.egg-info/requires.txt +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/requence.egg-info/top_level.txt +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/setup.cfg +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/tests/test_client_properties.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/tests/test_logger.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/tests/test_store_parity.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/tests/test_wire.py +0 -0
- {requence-0.8.1.dev98 → requence-0.8.2}/tests/test_wire_codec.py +0 -0
|
@@ -215,6 +215,23 @@ def _invocation_payload(invocation: dict, arg: Any) -> Any:
|
|
|
215
215
|
return {"arg": arg, "bound": invocation.get("bound")}
|
|
216
216
|
|
|
217
217
|
|
|
218
|
+
def _abort_message(error: BaseException) -> str:
|
|
219
|
+
"""The sentence the operator is told an `act()` failed with.
|
|
220
|
+
|
|
221
|
+
An `ExceptionGroup` from the settle-gate is unwrapped to its FIRST entry,
|
|
222
|
+
mirroring the TS side's `error.errors[0]` on an `AggregateError`. Its own
|
|
223
|
+
`str()` would do nearly the right thing — the boundary already builds the
|
|
224
|
+
group with the first failure's message — but `BaseExceptionGroup.__str__`
|
|
225
|
+
appends "(n sub-exceptions)", and this string is lifted verbatim into the
|
|
226
|
+
node's error message."""
|
|
227
|
+
first = (
|
|
228
|
+
error.exceptions[0]
|
|
229
|
+
if isinstance(error, BaseExceptionGroup) and error.exceptions
|
|
230
|
+
else error
|
|
231
|
+
)
|
|
232
|
+
return str(first) or type(first).__name__
|
|
233
|
+
|
|
234
|
+
|
|
218
235
|
def _unwrap_output_value(result: Any) -> Tuple[str | None, Any]:
|
|
219
236
|
"""Unwrap the `context.to_output(...)` wrapper into its output name and raw
|
|
220
237
|
value. Pure — serialization happens at the outbound boundary, not here."""
|
|
@@ -479,6 +496,21 @@ class Service:
|
|
|
479
496
|
self.__callbacks_lock = threading.Lock()
|
|
480
497
|
self.__callbacks: dict[str, dict[str, Any]] = dict()
|
|
481
498
|
|
|
499
|
+
# The defer keys an `act()` call is running for RIGHT NOW. Mutual
|
|
500
|
+
# exclusion, NOT a spend ledger: a defer key is not one-shot — the
|
|
501
|
+
# operator rewinds a deferred message's index space whenever the acting
|
|
502
|
+
# CONNECTION changes (`createStateMachine.ts`), precisely so a re-attach
|
|
503
|
+
# after a restart lands, and it is `done` that spends the key. A
|
|
504
|
+
# per-process set could not enforce one-shot anyway: a second worker, or
|
|
505
|
+
# this one after a restart, was never held by it. So every exit path
|
|
506
|
+
# releases the key — a call that threw did not spend it.
|
|
507
|
+
#
|
|
508
|
+
# Locked because `act()` is the one entry point an author calls from
|
|
509
|
+
# their own threads (a webhook worker, a durable handler, a REPL), so the
|
|
510
|
+
# check and the add have to be one step or two of them both pass.
|
|
511
|
+
self.__active_message_keys_lock = threading.Lock()
|
|
512
|
+
self.__active_message_keys: set[str] = set()
|
|
513
|
+
|
|
482
514
|
# What tells an author their registry is growing, and which `yield` is
|
|
483
515
|
# doing it (#151). Service-scoped because one of its two counters is: a
|
|
484
516
|
# worker holding fifty tasks at nine hundred callbacks each is the case no
|
|
@@ -1895,6 +1927,25 @@ class Service:
|
|
|
1895
1927
|
pass
|
|
1896
1928
|
|
|
1897
1929
|
def act(self, message_key: str, actor: Callable[[ActorApi], Any]):
|
|
1930
|
+
"""Re-attach to a deferred message and answer it.
|
|
1931
|
+
|
|
1932
|
+
The guard is mutual exclusion only — see `__active_message_keys`. It is
|
|
1933
|
+
released in a `finally` because a call that threw did not spend the key,
|
|
1934
|
+
and holding it would make this process refuse the one call that could
|
|
1935
|
+
still recover the message (a `done` marker lost to a dropped channel is
|
|
1936
|
+
exactly that call)."""
|
|
1937
|
+
with self.__active_message_keys_lock:
|
|
1938
|
+
if message_key in self.__active_message_keys:
|
|
1939
|
+
raise Exception("a defer key can only be used once")
|
|
1940
|
+
self.__active_message_keys.add(message_key)
|
|
1941
|
+
|
|
1942
|
+
try:
|
|
1943
|
+
self.__run_act(message_key, actor)
|
|
1944
|
+
finally:
|
|
1945
|
+
with self.__active_message_keys_lock:
|
|
1946
|
+
self.__active_message_keys.discard(message_key)
|
|
1947
|
+
|
|
1948
|
+
def __run_act(self, message_key: str, actor: Callable[[ActorApi], Any]):
|
|
1898
1949
|
# An actor's publish indices count from ZERO, and that is a contract with
|
|
1899
1950
|
# the operator, not a detail: `defer` CLEARS the message's result buffer
|
|
1900
1951
|
# ("defer resets the buffer because service packages cannot track the
|
|
@@ -2073,17 +2124,73 @@ class Service:
|
|
|
2073
2124
|
# send, which is the whole stretch this exists to make measurable.
|
|
2074
2125
|
self.__announce_resume(task_id, message_id)
|
|
2075
2126
|
|
|
2076
|
-
|
|
2127
|
+
def forget_callbacks():
|
|
2128
|
+
with self.__callbacks_lock:
|
|
2129
|
+
for callback_id in registered_callback_ids:
|
|
2130
|
+
if callback_id in self.__callbacks:
|
|
2131
|
+
del self.__callbacks[callback_id]
|
|
2132
|
+
|
|
2133
|
+
try:
|
|
2134
|
+
result = actor(api)
|
|
2077
2135
|
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2136
|
+
if inspect.isgenerator(result):
|
|
2137
|
+
for value in result:
|
|
2138
|
+
if value is not None:
|
|
2139
|
+
send(value)
|
|
2140
|
+
elif result is not None:
|
|
2141
|
+
send(result)
|
|
2084
2142
|
|
|
2085
|
-
|
|
2086
|
-
|
|
2143
|
+
# The done-gate: background stream bodies settle before the done marker.
|
|
2144
|
+
outbound.settle()
|
|
2145
|
+
except Exception as error:
|
|
2146
|
+
# Every failure between the resume row and the done marker lands
|
|
2147
|
+
# here, and they all leave the same wreckage: whatever the actor
|
|
2148
|
+
# already sent is published AND already dispatched downstream (the
|
|
2149
|
+
# buffer is contiguous from 0 and `deferred` satisfies the begin
|
|
2150
|
+
# check), while the emission that ended the actor never happened.
|
|
2151
|
+
# Half an answer, and nothing on the wire says which half.
|
|
2152
|
+
#
|
|
2153
|
+
# Re-attaching is not a way out of that, on either connection:
|
|
2154
|
+
#
|
|
2155
|
+
# - On a NEW connection the operator rewinds the deferred index space
|
|
2156
|
+
# (`createStateMachine.ts`, keyed on the acting connection), so the
|
|
2157
|
+
# re-publish lands — but `used` is deliberately NOT reset, so on a
|
|
2158
|
+
# LINEAR node the first re-published data trips the "cannot send
|
|
2159
|
+
# multiple times in linear mode" guard and fails the node with a
|
|
2160
|
+
# message that names the wrong problem.
|
|
2161
|
+
# - On the SAME connection nothing rewinds: every re-publish is
|
|
2162
|
+
# discarded as a duplicate index and only the done marker lands,
|
|
2163
|
+
# quietly completing the node with the FIRST attempt's data.
|
|
2164
|
+
#
|
|
2165
|
+
# So fail the node here, deliberately and with the actor's own error,
|
|
2166
|
+
# rather than park it and let one of those two find it later. Same
|
|
2167
|
+
# arm the TS SDK grew (`createAmqpConnection.ts`); Python had neither
|
|
2168
|
+
# half of it, so an actor that threw left the node deferred forever
|
|
2169
|
+
# with nothing logged anywhere.
|
|
2170
|
+
#
|
|
2171
|
+
# `BaseException` is deliberately NOT caught: a KeyboardInterrupt or a
|
|
2172
|
+
# `sys.exit()` inside an actor is the caller ending the process, not a
|
|
2173
|
+
# node failing, and failing their task on Ctrl-C would be a surprise
|
|
2174
|
+
# the TS side has no equivalent of. Those still release the defer key
|
|
2175
|
+
# — that is the outer `finally`, which catches everything.
|
|
2176
|
+
forget_callbacks()
|
|
2177
|
+
try:
|
|
2178
|
+
abort(_abort_message(error))
|
|
2179
|
+
# `abort` only SCHEDULES its publish, so the barrier the done
|
|
2180
|
+
# marker needs applies to the failure report too: `act()` may be
|
|
2181
|
+
# the last thing this process does, and the consume thread is a
|
|
2182
|
+
# daemon.
|
|
2183
|
+
self.__flush()
|
|
2184
|
+
except Exception as abort_error:
|
|
2185
|
+
# The channel that would carry the abort is usually the reason we
|
|
2186
|
+
# are here at all. Keep the original error as the one the caller
|
|
2187
|
+
# sees — it is the diagnosis — and log this one: a lost abort only
|
|
2188
|
+
# leaves the node deferred, which is where it already was.
|
|
2189
|
+
logger.error(
|
|
2190
|
+
"Requence act() could not report its failure to the operator:",
|
|
2191
|
+
abort_error,
|
|
2192
|
+
)
|
|
2193
|
+
raise
|
|
2087
2194
|
|
|
2088
2195
|
self.__schedule(functools.partial(self.__publish, message_id=message_id, task_id=task_id, index=next_index(), headers={"done": True}))
|
|
2089
2196
|
|
|
@@ -2093,7 +2200,4 @@ class Service:
|
|
|
2093
2200
|
# sent.
|
|
2094
2201
|
self.__flush()
|
|
2095
2202
|
|
|
2096
|
-
|
|
2097
|
-
for callback_id in registered_callback_ids:
|
|
2098
|
-
if (callback_id in self.__callbacks):
|
|
2099
|
-
del self.__callbacks[callback_id]
|
|
2203
|
+
forget_callbacks()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|