flo-python 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
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.
- flo/__init__.py +15 -3
- flo/actions.py +10 -9
- flo/exceptions.py +10 -0
- flo/kv.py +2 -1
- flo/kv_body.py +34 -6
- flo/processing.py +63 -35
- flo/streams.py +33 -8
- flo/types.py +106 -25
- flo/wire.py +4 -3
- flo/workflows.py +173 -24
- {flo_python-0.1.3.dist-info → flo_python-0.1.4.dist-info}/METADATA +16 -7
- flo_python-0.1.4.dist-info/RECORD +19 -0
- flo_python-0.1.3.dist-info/RECORD +0 -19
- {flo_python-0.1.3.dist-info → flo_python-0.1.4.dist-info}/WHEEL +0 -0
- {flo_python-0.1.3.dist-info → flo_python-0.1.4.dist-info}/licenses/LICENSE +0 -0
flo/__init__.py
CHANGED
|
@@ -46,6 +46,7 @@ from .exceptions import (
|
|
|
46
46
|
InvalidMagicError,
|
|
47
47
|
KeyTooLargeError,
|
|
48
48
|
NamespaceTooLargeError,
|
|
49
|
+
NoNamespaceError,
|
|
49
50
|
NonRetryableError,
|
|
50
51
|
NotConnectedError,
|
|
51
52
|
NotFoundError,
|
|
@@ -71,7 +72,6 @@ from .retry import DEFAULT_RETRY_POLICY, RetryPolicy
|
|
|
71
72
|
from .types import (
|
|
72
73
|
AckOptions,
|
|
73
74
|
ActionDeleteOptions,
|
|
74
|
-
ActionInfo,
|
|
75
75
|
ActionInvokeOptions,
|
|
76
76
|
ActionInvokeResult,
|
|
77
77
|
ActionListOptions,
|
|
@@ -111,6 +111,7 @@ from .types import (
|
|
|
111
111
|
ProcessingCancelOptions,
|
|
112
112
|
ProcessingListEntry,
|
|
113
113
|
ProcessingListOptions,
|
|
114
|
+
ProcessingListResult,
|
|
114
115
|
ProcessingStatusOptions,
|
|
115
116
|
ProcessingStatusResult,
|
|
116
117
|
ProcessingStopOptions,
|
|
@@ -130,6 +131,7 @@ from .types import (
|
|
|
130
131
|
StreamAppendOptions,
|
|
131
132
|
StreamAppendResult,
|
|
132
133
|
StreamClaimResult,
|
|
134
|
+
StreamDeleteOptions,
|
|
133
135
|
StreamGroupAckOptions,
|
|
134
136
|
StreamGroupJoinOptions,
|
|
135
137
|
StreamGroupNackOptions,
|
|
@@ -160,12 +162,16 @@ from .types import (
|
|
|
160
162
|
WorkerType,
|
|
161
163
|
WorkflowCancelOptions,
|
|
162
164
|
WorkflowCreateOptions,
|
|
165
|
+
WorkflowDefinitionEntry,
|
|
163
166
|
WorkflowDisableOptions,
|
|
164
167
|
WorkflowEnableOptions,
|
|
165
168
|
WorkflowGetDefinitionOptions,
|
|
166
169
|
WorkflowHistoryOptions,
|
|
167
170
|
WorkflowListDefinitionsOptions,
|
|
171
|
+
WorkflowListDefinitionsResult,
|
|
168
172
|
WorkflowListRunsOptions,
|
|
173
|
+
WorkflowListRunsResult,
|
|
174
|
+
WorkflowRunEntry,
|
|
169
175
|
WorkflowSignalOptions,
|
|
170
176
|
WorkflowStartOptions,
|
|
171
177
|
WorkflowStatusOptions,
|
|
@@ -184,7 +190,7 @@ from .worker import (
|
|
|
184
190
|
)
|
|
185
191
|
from .workflows import WorkflowOperations
|
|
186
192
|
|
|
187
|
-
__version__ = "0.1.
|
|
193
|
+
__version__ = "0.1.4"
|
|
188
194
|
|
|
189
195
|
__all__ = [
|
|
190
196
|
"Transaction",
|
|
@@ -240,6 +246,7 @@ __all__ = [
|
|
|
240
246
|
"BlockTooLongError",
|
|
241
247
|
"ServerError",
|
|
242
248
|
"NotFoundError",
|
|
249
|
+
"NoNamespaceError",
|
|
243
250
|
"BadRequestError",
|
|
244
251
|
"ConflictError",
|
|
245
252
|
"UnauthorizedError",
|
|
@@ -292,6 +299,7 @@ __all__ = [
|
|
|
292
299
|
"StreamTrimOptions",
|
|
293
300
|
"StreamTrimResult",
|
|
294
301
|
"StreamInfoOptions",
|
|
302
|
+
"StreamDeleteOptions",
|
|
295
303
|
"StreamGroupJoinOptions",
|
|
296
304
|
"StreamGroupReadOptions",
|
|
297
305
|
"StreamGroupAckOptions",
|
|
@@ -299,7 +307,6 @@ __all__ = [
|
|
|
299
307
|
# Action types
|
|
300
308
|
"ActionType",
|
|
301
309
|
"RunStatus",
|
|
302
|
-
"ActionInfo",
|
|
303
310
|
"ActionRunStatus",
|
|
304
311
|
"ActionInvokeResult",
|
|
305
312
|
"ActionListResult",
|
|
@@ -336,7 +343,11 @@ __all__ = [
|
|
|
336
343
|
"WorkflowCancelOptions",
|
|
337
344
|
"WorkflowHistoryOptions",
|
|
338
345
|
"WorkflowListRunsOptions",
|
|
346
|
+
"WorkflowListRunsResult",
|
|
347
|
+
"WorkflowRunEntry",
|
|
339
348
|
"WorkflowListDefinitionsOptions",
|
|
349
|
+
"WorkflowListDefinitionsResult",
|
|
350
|
+
"WorkflowDefinitionEntry",
|
|
340
351
|
"WorkflowDisableOptions",
|
|
341
352
|
"WorkflowEnableOptions",
|
|
342
353
|
"WorkflowSyncOptions",
|
|
@@ -351,5 +362,6 @@ __all__ = [
|
|
|
351
362
|
"ProcessingSyncOptions",
|
|
352
363
|
"ProcessingStatusResult",
|
|
353
364
|
"ProcessingListEntry",
|
|
365
|
+
"ProcessingListResult",
|
|
354
366
|
"ProcessingSyncResult",
|
|
355
367
|
]
|
flo/actions.py
CHANGED
|
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING
|
|
|
11
11
|
|
|
12
12
|
from .kv_body import (
|
|
13
13
|
decode_action_invoke_answer,
|
|
14
|
+
decode_action_list_answer,
|
|
14
15
|
decode_action_status_answer,
|
|
15
16
|
decode_worker_info_answer,
|
|
16
17
|
decode_worker_list_answer,
|
|
@@ -159,28 +160,28 @@ class ActionOperations:
|
|
|
159
160
|
self,
|
|
160
161
|
options: ActionListOptions | None = None,
|
|
161
162
|
) -> ActionListResult:
|
|
162
|
-
"""List registered actions.
|
|
163
|
+
"""List a page of the namespace's registered actions.
|
|
163
164
|
|
|
164
165
|
Args:
|
|
165
|
-
options:
|
|
166
|
+
options: The page's limit and cursor (the last page's ``cursor``;
|
|
167
|
+
None starts).
|
|
166
168
|
|
|
167
169
|
Returns:
|
|
168
|
-
ActionListResult with
|
|
170
|
+
ActionListResult with the page's action names and the next
|
|
171
|
+
page's cursor, None on the last page.
|
|
169
172
|
"""
|
|
170
173
|
opts = options or ActionListOptions()
|
|
171
174
|
namespace = self._client.get_namespace(opts.namespace)
|
|
172
175
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
await self._client._send_and_check(
|
|
176
|
+
response = await self._client._send_and_check(
|
|
176
177
|
OpCode.ACTION_LIST,
|
|
177
178
|
namespace,
|
|
178
179
|
(opts.prefix or "").encode("utf-8"),
|
|
179
|
-
|
|
180
|
+
serialize_action_list_value(limit=opts.limit, cursor=opts.cursor),
|
|
180
181
|
)
|
|
181
182
|
|
|
182
|
-
|
|
183
|
-
return ActionListResult(
|
|
183
|
+
names, cursor = decode_action_list_answer(response.data)
|
|
184
|
+
return ActionListResult(names=names, cursor=cursor)
|
|
184
185
|
|
|
185
186
|
async def delete(
|
|
186
187
|
self,
|
flo/exceptions.py
CHANGED
|
@@ -191,6 +191,15 @@ class StaleNotFoundError(NotFoundError):
|
|
|
191
191
|
stale = True
|
|
192
192
|
|
|
193
193
|
|
|
194
|
+
class NoNamespaceError(ServerError):
|
|
195
|
+
"""The namespace the request names doesn't exist. Not a NotFoundError,
|
|
196
|
+
which means a missing key, so a missing namespace never reads as an
|
|
197
|
+
absent key."""
|
|
198
|
+
|
|
199
|
+
def __init__(self, message: str = StatusCode.NO_NAMESPACE.message()):
|
|
200
|
+
super().__init__(message, StatusCode.NO_NAMESPACE)
|
|
201
|
+
|
|
202
|
+
|
|
194
203
|
class BadRequestError(ServerError):
|
|
195
204
|
"""Invalid request parameters."""
|
|
196
205
|
|
|
@@ -311,6 +320,7 @@ def _error_for(status: StatusCode, message: str) -> ServerError:
|
|
|
311
320
|
|
|
312
321
|
error_map: dict[StatusCode, Callable[[str], ServerError]] = {
|
|
313
322
|
StatusCode.NOT_FOUND: NotFoundError,
|
|
323
|
+
StatusCode.NO_NAMESPACE: NoNamespaceError,
|
|
314
324
|
StatusCode.BAD_REQUEST: BadRequestError,
|
|
315
325
|
StatusCode.CONFLICT: ConflictError,
|
|
316
326
|
StatusCode.UNAUTHORIZED: UnauthorizedError,
|
flo/kv.py
CHANGED
|
@@ -207,6 +207,7 @@ class KVOperations:
|
|
|
207
207
|
when it has none. ``stale`` says a halted shard answered.
|
|
208
208
|
|
|
209
209
|
Raises:
|
|
210
|
+
NoNamespaceError: The namespace was never created.
|
|
210
211
|
StaleNotFoundError: A halted shard had no such key as of the entry
|
|
211
212
|
it halted at; it may exist since.
|
|
212
213
|
|
|
@@ -323,7 +324,7 @@ class KVOperations:
|
|
|
323
324
|
result = await client.kv.scan("user:", opts)
|
|
324
325
|
for name in result.names:
|
|
325
326
|
print(name)
|
|
326
|
-
if result.cursor is None
|
|
327
|
+
if result.cursor is None:
|
|
327
328
|
break
|
|
328
329
|
opts = ScanOptions(cursor=result.cursor)
|
|
329
330
|
"""
|
flo/kv_body.py
CHANGED
|
@@ -39,7 +39,9 @@ from .types import (
|
|
|
39
39
|
_MAX_ROUTING_KEY = 4096
|
|
40
40
|
_MAX_JSON_PATH = 1024
|
|
41
41
|
_MAX_JSON_DOCUMENT = 252_819
|
|
42
|
-
|
|
42
|
+
# A scan's cursor: the shard it stopped on (u16), then the last key it
|
|
43
|
+
# returned; its length prefix is a u16.
|
|
44
|
+
_MAX_SCAN_CURSOR = 2 + 4096
|
|
43
45
|
MAX_SCAN = 1024
|
|
44
46
|
MAX_MGET = 256
|
|
45
47
|
# The most bytes of mget key elements (each [len:u16][key]) in one request:
|
|
@@ -47,6 +49,7 @@ MAX_MGET = 256
|
|
|
47
49
|
MAX_MGET_KEYS_BYTES = 253_848
|
|
48
50
|
MAX_HISTORY = 65
|
|
49
51
|
MAX_WORKER_LIST = 1024
|
|
52
|
+
MAX_ACTION_LIST = 1024
|
|
50
53
|
MAX_WORKER_PROCESSES = 1024
|
|
51
54
|
_MAX_WORKER_ID = 4096
|
|
52
55
|
# The longest TTL whose nanoseconds fit a u64.
|
|
@@ -175,10 +178,9 @@ def encode_delete_body(
|
|
|
175
178
|
|
|
176
179
|
def encode_scan_body(limit: int, cursor: bytes | None) -> bytes:
|
|
177
180
|
"""kv.scan's request: limit, cursor (empty for the first page)."""
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return _limit("scan limit", limit, MAX_SCAN) + bytes([len(cursor)]) + cursor
|
|
181
|
+
return _limit("scan limit", limit, MAX_SCAN) + _bytes16(
|
|
182
|
+
"scan cursor", cursor or b"", _MAX_SCAN_CURSOR
|
|
183
|
+
)
|
|
182
184
|
|
|
183
185
|
|
|
184
186
|
def encode_history_body(limit: int, before_version: int | None, routing_key: str | None) -> bytes:
|
|
@@ -370,7 +372,7 @@ def decode_scan_answer(data: bytes) -> tuple[list[str], bytes | None]:
|
|
|
370
372
|
names = [a.bytes16().decode("utf-8") for _ in range(a.u16())]
|
|
371
373
|
except UnicodeDecodeError as e:
|
|
372
374
|
raise IncompleteResponseError("kv.scan answer has a name that isn't UTF-8") from e
|
|
373
|
-
cursor = a.
|
|
375
|
+
cursor = a.bytes16() if a.present() else None
|
|
374
376
|
a.done()
|
|
375
377
|
return names, cursor
|
|
376
378
|
|
|
@@ -522,6 +524,32 @@ def decode_action_invoke_answer(data: bytes) -> str:
|
|
|
522
524
|
return run_id.decode("utf-8")
|
|
523
525
|
|
|
524
526
|
|
|
527
|
+
def decode_action_list_answer(data: bytes) -> tuple[list[str], bytes | None]:
|
|
528
|
+
"""action.list's answer: [count:u32]([name_len:u16][name][value_len:u32][value])*
|
|
529
|
+
[has_more:u8][cursor_len:u16][cursor]. Returns the names and the next
|
|
530
|
+
page's cursor, None on the last page; the values aren't read."""
|
|
531
|
+
op = "action.list"
|
|
532
|
+
a = _Answer(op, data)
|
|
533
|
+
count = a.u32()
|
|
534
|
+
if count > MAX_ACTION_LIST:
|
|
535
|
+
raise IncompleteResponseError(f"{op} answer lists {count} actions")
|
|
536
|
+
names = []
|
|
537
|
+
for _ in range(count):
|
|
538
|
+
try:
|
|
539
|
+
names.append(a.bytes16().decode("utf-8"))
|
|
540
|
+
except UnicodeDecodeError as e:
|
|
541
|
+
raise IncompleteResponseError(f"{op} answer has a name that isn't UTF-8") from e
|
|
542
|
+
a.bytes32()
|
|
543
|
+
has_more = a.flag()
|
|
544
|
+
cursor = a.bytes16()
|
|
545
|
+
a.done()
|
|
546
|
+
if has_more and not cursor:
|
|
547
|
+
raise IncompleteResponseError(f"{op} answer has more pages but no cursor")
|
|
548
|
+
if not has_more and cursor:
|
|
549
|
+
raise IncompleteResponseError(f"{op} answer has a cursor on its last page")
|
|
550
|
+
return names, cursor if has_more else None
|
|
551
|
+
|
|
552
|
+
|
|
525
553
|
_E = TypeVar("_E", WorkerType, WorkerStatus, ProcessKind)
|
|
526
554
|
|
|
527
555
|
|
flo/processing.py
CHANGED
|
@@ -17,6 +17,7 @@ from .types import (
|
|
|
17
17
|
ProcessingCancelOptions,
|
|
18
18
|
ProcessingListEntry,
|
|
19
19
|
ProcessingListOptions,
|
|
20
|
+
ProcessingListResult,
|
|
20
21
|
ProcessingStatusOptions,
|
|
21
22
|
ProcessingStatusResult,
|
|
22
23
|
ProcessingStopOptions,
|
|
@@ -29,6 +30,8 @@ if TYPE_CHECKING:
|
|
|
29
30
|
from .client import FloClient
|
|
30
31
|
|
|
31
32
|
_PROCESSING_STATUS_NAMES = ["running", "stopped", "cancelled", "failed", "completed"]
|
|
33
|
+
# The most jobs one list page holds.
|
|
34
|
+
_MAX_PROCESSING_LIST = 1024
|
|
32
35
|
|
|
33
36
|
|
|
34
37
|
class ProcessingOperations:
|
|
@@ -62,7 +65,11 @@ class ProcessingOperations:
|
|
|
62
65
|
async def status(
|
|
63
66
|
self, job_id: str, options: ProcessingStatusOptions | None = None
|
|
64
67
|
) -> ProcessingStatusResult | None:
|
|
65
|
-
"""Get the status of a processing job. Returns None if not found.
|
|
68
|
+
"""Get the status of a processing job. Returns None if not found.
|
|
69
|
+
|
|
70
|
+
Raises:
|
|
71
|
+
NoNamespaceError: The namespace was never created.
|
|
72
|
+
"""
|
|
66
73
|
opts = options or ProcessingStatusOptions()
|
|
67
74
|
namespace = self._client.get_namespace(opts.namespace)
|
|
68
75
|
|
|
@@ -81,14 +88,22 @@ class ProcessingOperations:
|
|
|
81
88
|
|
|
82
89
|
return _parse_processing_status(resp.data)
|
|
83
90
|
|
|
84
|
-
async def list(self, options: ProcessingListOptions | None = None) ->
|
|
85
|
-
"""List processing jobs.
|
|
91
|
+
async def list(self, options: ProcessingListOptions | None = None) -> ProcessingListResult:
|
|
92
|
+
"""List a page of the namespace's processing jobs.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
options: The page's limit and cursor (the last page's ``cursor``;
|
|
96
|
+
None starts).
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
ProcessingListResult with the page's jobs and the next page's
|
|
100
|
+
cursor, None on the last page.
|
|
101
|
+
"""
|
|
86
102
|
opts = options or ProcessingListOptions()
|
|
87
103
|
namespace = self._client.get_namespace(opts.namespace)
|
|
88
104
|
|
|
89
105
|
# Wire format: [limit:u32][cursor...]
|
|
90
|
-
|
|
91
|
-
value = struct.pack("<I", opts.limit) + cursor
|
|
106
|
+
value = struct.pack("<I", opts.limit) + (opts.cursor or b"")
|
|
92
107
|
|
|
93
108
|
resp = await self._client._send_and_check(
|
|
94
109
|
OpCode.PROCESSING_LIST,
|
|
@@ -97,7 +112,8 @@ class ProcessingOperations:
|
|
|
97
112
|
value,
|
|
98
113
|
)
|
|
99
114
|
|
|
100
|
-
|
|
115
|
+
entries, next_cursor = _parse_processing_list(resp.data)
|
|
116
|
+
return ProcessingListResult(jobs=entries, cursor=next_cursor)
|
|
101
117
|
|
|
102
118
|
async def stop(self, job_id: str, options: ProcessingStopOptions | None = None) -> None:
|
|
103
119
|
"""Gracefully stop a processing job."""
|
|
@@ -217,50 +233,62 @@ def _parse_processing_status(data: bytes) -> ProcessingStatusResult:
|
|
|
217
233
|
)
|
|
218
234
|
|
|
219
235
|
|
|
220
|
-
def _parse_processing_list(data: bytes) -> list[ProcessingListEntry]:
|
|
221
|
-
"""Parse binary wire format for processing job list
|
|
236
|
+
def _parse_processing_list(data: bytes) -> tuple[list[ProcessingListEntry], bytes | None]:
|
|
237
|
+
"""Parse binary wire format for processing job list: the page's jobs and
|
|
238
|
+
the next page's cursor, None on the last page.
|
|
222
239
|
|
|
223
240
|
Wire format: [count:u32]([name_len:u16][name][job_id_len:u16][job_id]
|
|
224
241
|
[status_len:u16][status][created_at:i64])*
|
|
242
|
+
[has_more:u8][cursor_len:u16][cursor]
|
|
243
|
+
A failed job's status reads "FAILED: <reason>".
|
|
225
244
|
"""
|
|
226
|
-
|
|
227
|
-
return []
|
|
228
|
-
|
|
229
|
-
(count,) = struct.unpack_from("<I", data, 0)
|
|
230
|
-
pos = 4
|
|
231
|
-
results: list[ProcessingListEntry] = []
|
|
245
|
+
pos = 0
|
|
232
246
|
|
|
233
|
-
def
|
|
247
|
+
def take(n: int) -> bytes:
|
|
234
248
|
nonlocal pos
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
249
|
+
if pos + n > len(data):
|
|
250
|
+
raise IncompleteResponseError("processing.list answer is truncated")
|
|
251
|
+
b = data[pos : pos + n]
|
|
252
|
+
pos += n
|
|
253
|
+
return b
|
|
238
254
|
|
|
239
255
|
def read_str() -> str:
|
|
240
|
-
n =
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
256
|
+
(n,) = struct.unpack("<H", take(2))
|
|
257
|
+
raw = take(n)
|
|
258
|
+
try:
|
|
259
|
+
return raw.decode("utf-8")
|
|
260
|
+
except UnicodeDecodeError as e:
|
|
261
|
+
raise IncompleteResponseError(
|
|
262
|
+
"processing.list answer has a field that isn't UTF-8"
|
|
263
|
+
) from e
|
|
245
264
|
|
|
265
|
+
(count,) = struct.unpack("<I", take(4))
|
|
266
|
+
if count > _MAX_PROCESSING_LIST:
|
|
267
|
+
raise IncompleteResponseError(f"processing.list answer lists {count} jobs")
|
|
268
|
+
entries: list[ProcessingListEntry] = []
|
|
246
269
|
for _ in range(count):
|
|
247
270
|
name = read_str()
|
|
248
271
|
job_id = read_str()
|
|
249
272
|
status = read_str()
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
results.append(
|
|
255
|
-
ProcessingListEntry(
|
|
256
|
-
name=name,
|
|
257
|
-
job_id=job_id,
|
|
258
|
-
status=status,
|
|
259
|
-
created_at=created_at,
|
|
260
|
-
)
|
|
273
|
+
(created_at,) = struct.unpack("<q", take(8))
|
|
274
|
+
entries.append(
|
|
275
|
+
ProcessingListEntry(name=name, job_id=job_id, status=status, created_at=created_at)
|
|
261
276
|
)
|
|
262
277
|
|
|
263
|
-
|
|
278
|
+
has_more = take(1)[0]
|
|
279
|
+
if has_more > 1:
|
|
280
|
+
raise IncompleteResponseError(f"processing.list answer has a has_more of {has_more}")
|
|
281
|
+
(cursor_len,) = struct.unpack("<H", take(2))
|
|
282
|
+
cursor = take(cursor_len)
|
|
283
|
+
if pos != len(data):
|
|
284
|
+
raise IncompleteResponseError(
|
|
285
|
+
f"processing.list answer has {len(data) - pos} bytes after the cursor"
|
|
286
|
+
)
|
|
287
|
+
if has_more and not cursor:
|
|
288
|
+
raise IncompleteResponseError("processing.list answer has more pages but no cursor")
|
|
289
|
+
if not has_more and cursor:
|
|
290
|
+
raise IncompleteResponseError("processing.list answer has a cursor on its last page")
|
|
291
|
+
return entries, cursor if has_more else None
|
|
264
292
|
|
|
265
293
|
|
|
266
294
|
# =============================================================================
|
flo/streams.py
CHANGED
|
@@ -14,6 +14,7 @@ from .types import (
|
|
|
14
14
|
StreamAppendOptions,
|
|
15
15
|
StreamAppendResult,
|
|
16
16
|
StreamClaimResult,
|
|
17
|
+
StreamDeleteOptions,
|
|
17
18
|
StreamGroupAckOptions,
|
|
18
19
|
StreamGroupJoinOptions,
|
|
19
20
|
StreamGroupNackOptions,
|
|
@@ -82,7 +83,6 @@ class StreamOperations:
|
|
|
82
83
|
namespace,
|
|
83
84
|
stream.encode("utf-8"),
|
|
84
85
|
value,
|
|
85
|
-
allow_not_found=True,
|
|
86
86
|
)
|
|
87
87
|
|
|
88
88
|
return parse_stream_append_response(response.data)
|
|
@@ -155,7 +155,6 @@ class StreamOperations:
|
|
|
155
155
|
stream.encode("utf-8"),
|
|
156
156
|
b"",
|
|
157
157
|
builder.build(),
|
|
158
|
-
allow_not_found=True,
|
|
159
158
|
)
|
|
160
159
|
|
|
161
160
|
return parse_stream_read_response(response.data)
|
|
@@ -174,6 +173,10 @@ class StreamOperations:
|
|
|
174
173
|
Returns:
|
|
175
174
|
StreamInfo with first_id, last_id, count, bytes_size.
|
|
176
175
|
|
|
176
|
+
Raises:
|
|
177
|
+
NotFoundError: No such stream.
|
|
178
|
+
NoNamespaceError: The namespace was never created.
|
|
179
|
+
|
|
177
180
|
Example:
|
|
178
181
|
info = await client.stream.info("events")
|
|
179
182
|
print(f"Stream has {info.count} records ({info.bytes_size} bytes)")
|
|
@@ -186,7 +189,6 @@ class StreamOperations:
|
|
|
186
189
|
namespace,
|
|
187
190
|
stream.encode("utf-8"),
|
|
188
191
|
b"",
|
|
189
|
-
allow_not_found=True,
|
|
190
192
|
)
|
|
191
193
|
|
|
192
194
|
return parse_stream_info_response(response.data)
|
|
@@ -239,6 +241,34 @@ class StreamOperations:
|
|
|
239
241
|
removed, first_seq = struct.unpack("<QQ", response.data)
|
|
240
242
|
return StreamTrimResult(removed=removed, first_seq=first_seq)
|
|
241
243
|
|
|
244
|
+
async def delete(
|
|
245
|
+
self,
|
|
246
|
+
stream: str,
|
|
247
|
+
options: StreamDeleteOptions | None = None,
|
|
248
|
+
) -> None:
|
|
249
|
+
"""Delete a stream's records and metadata.
|
|
250
|
+
|
|
251
|
+
Deleting a stream that doesn't exist succeeds. A stream that still has
|
|
252
|
+
records is refused with ``ConflictError`` unless ``force`` is set.
|
|
253
|
+
|
|
254
|
+
Example:
|
|
255
|
+
await client.stream.delete("events", StreamDeleteOptions(force=True))
|
|
256
|
+
"""
|
|
257
|
+
opts = options or StreamDeleteOptions()
|
|
258
|
+
namespace = self._client.get_namespace(opts.namespace)
|
|
259
|
+
|
|
260
|
+
builder = OptionsBuilder()
|
|
261
|
+
if opts.force:
|
|
262
|
+
builder.add_flag(OptionTag.FORCE)
|
|
263
|
+
|
|
264
|
+
await self._client._send_and_check(
|
|
265
|
+
OpCode.STREAM_DELETE,
|
|
266
|
+
namespace,
|
|
267
|
+
stream.encode("utf-8"),
|
|
268
|
+
b"",
|
|
269
|
+
builder.build(),
|
|
270
|
+
)
|
|
271
|
+
|
|
242
272
|
async def group_join(
|
|
243
273
|
self,
|
|
244
274
|
stream: str,
|
|
@@ -267,7 +297,6 @@ class StreamOperations:
|
|
|
267
297
|
namespace,
|
|
268
298
|
stream.encode("utf-8"),
|
|
269
299
|
value,
|
|
270
|
-
allow_not_found=True,
|
|
271
300
|
)
|
|
272
301
|
|
|
273
302
|
async def group_leave(
|
|
@@ -298,7 +327,6 @@ class StreamOperations:
|
|
|
298
327
|
namespace,
|
|
299
328
|
stream.encode("utf-8"),
|
|
300
329
|
value,
|
|
301
|
-
allow_not_found=True,
|
|
302
330
|
)
|
|
303
331
|
|
|
304
332
|
async def group_read(
|
|
@@ -356,7 +384,6 @@ class StreamOperations:
|
|
|
356
384
|
stream.encode("utf-8"),
|
|
357
385
|
value,
|
|
358
386
|
builder.build(),
|
|
359
|
-
allow_not_found=True,
|
|
360
387
|
)
|
|
361
388
|
|
|
362
389
|
return parse_stream_read_response(response.data)
|
|
@@ -386,7 +413,6 @@ class StreamOperations:
|
|
|
386
413
|
namespace,
|
|
387
414
|
stream.encode("utf-8"),
|
|
388
415
|
value,
|
|
389
|
-
allow_not_found=True,
|
|
390
416
|
)
|
|
391
417
|
|
|
392
418
|
return parse_pending_entries(response.data)
|
|
@@ -432,7 +458,6 @@ class StreamOperations:
|
|
|
432
458
|
namespace,
|
|
433
459
|
stream.encode("utf-8"),
|
|
434
460
|
value,
|
|
435
|
-
allow_not_found=True,
|
|
436
461
|
)
|
|
437
462
|
|
|
438
463
|
# Response = <records blob> + [next_ts:u64][next_seq:u64] trailer.
|
flo/types.py
CHANGED
|
@@ -18,7 +18,7 @@ VERSION: int = 0x03
|
|
|
18
18
|
# header. A server built from another table refuses the request, and its
|
|
19
19
|
# answers carry its own hash, which this SDK refuses. CI's live tests run
|
|
20
20
|
# against the flo commit in .github/flo-ref.env: change both in one commit.
|
|
21
|
-
TABLE_HASH: int =
|
|
21
|
+
TABLE_HASH: int = 0xC751512225A42D04
|
|
22
22
|
# Response header flag: a halted shard answered a read from the state just
|
|
23
23
|
# before the entry it halted at. The read succeeded.
|
|
24
24
|
RESPONSE_STALE: int = 0x01
|
|
@@ -79,6 +79,8 @@ class Reason(IntEnum):
|
|
|
79
79
|
# The shard halted at an entry every replica fails the same way; it takes
|
|
80
80
|
# no writes until an operator repairs it.
|
|
81
81
|
SHARD_HALTED = 29
|
|
82
|
+
# The op is served only on a node's admin socket.
|
|
83
|
+
ADMIN_ONLY = 30
|
|
82
84
|
|
|
83
85
|
|
|
84
86
|
class Ran(IntEnum):
|
|
@@ -131,17 +133,16 @@ class OpCode(IntEnum):
|
|
|
131
133
|
NAMESPACE_DELETE = 0x011
|
|
132
134
|
NAMESPACE_LIST = 0x012
|
|
133
135
|
NAMESPACE_INFO = 0x013
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
# Sent by one shard to another, never by a client.
|
|
137
|
+
NAMESPACE_ENSURE = 0x016
|
|
136
138
|
|
|
137
139
|
# ── Cluster (0x030 – 0x04F) ──
|
|
138
140
|
CLUSTER_STATUS = 0x030
|
|
139
141
|
CLUSTER_MEMBERS = 0x031
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
CLUSTER_REMOVE_NODE = 0x036
|
|
142
|
+
CLUSTER_PROMOTE = 0x032
|
|
143
|
+
CLUSTER_REMOVE = 0x033
|
|
144
|
+
# Served only on a node's admin socket.
|
|
145
|
+
CLUSTER_REPAIR_SKIP = 0x034
|
|
145
146
|
|
|
146
147
|
# ── KV (0x100 – 0x12F) ──
|
|
147
148
|
KV_PUT = 0x100
|
|
@@ -171,6 +172,7 @@ class OpCode(IntEnum):
|
|
|
171
172
|
STREAM_LIST = 0x13B
|
|
172
173
|
STREAM_CREATE = 0x13D
|
|
173
174
|
STREAM_ALTER = 0x13F
|
|
175
|
+
STREAM_DELETE = 0x140
|
|
174
176
|
|
|
175
177
|
# ── Stream Consumer Groups (0x150 – 0x16F) ──
|
|
176
178
|
STREAM_GROUP_CREATE = 0x150
|
|
@@ -268,6 +270,9 @@ class StatusCode(IntEnum):
|
|
|
268
270
|
# The write committed but hasn't applied: its shard halted at or before
|
|
269
271
|
# it. Resending it would write it twice, or halt again.
|
|
270
272
|
OUTCOME_PENDING = 13
|
|
273
|
+
# The namespace the request names doesn't exist; NOT_FOUND means a
|
|
274
|
+
# missing key.
|
|
275
|
+
NO_NAMESPACE = 14
|
|
271
276
|
|
|
272
277
|
@classmethod
|
|
273
278
|
def _missing_(cls, value: object) -> "StatusCode | None":
|
|
@@ -306,6 +311,7 @@ class StatusCode(IntEnum):
|
|
|
306
311
|
StatusCode.OUTCOME_PENDING: (
|
|
307
312
|
"Committed, not applied: its shard halted; don't resend it unchanged"
|
|
308
313
|
),
|
|
314
|
+
StatusCode.NO_NAMESPACE: "Namespace not found",
|
|
309
315
|
}
|
|
310
316
|
return messages.get(self, f"Unknown status {int(self)}")
|
|
311
317
|
|
|
@@ -334,6 +340,7 @@ class OptionTag(IntEnum):
|
|
|
334
340
|
PARTITION_KEY = 0x25 # string: Key for partition routing
|
|
335
341
|
MAX_AGE_SECONDS = 0x26 # u64: Maximum age in seconds for retention
|
|
336
342
|
DRY_RUN = 0x28 # void: Flag to preview what would be deleted
|
|
343
|
+
FORCE = 0x2C # void: Flag to delete a stream that still has records
|
|
337
344
|
|
|
338
345
|
# Consumer Group Options (0x30 - 0x3F)
|
|
339
346
|
ACK_TIMEOUT_MS = 0x30 # u32: Time before unacked message auto-redelivers
|
|
@@ -854,6 +861,14 @@ class StreamTrimResult:
|
|
|
854
861
|
first_seq: int # Sequence of the first record left; meaningful only when records remain
|
|
855
862
|
|
|
856
863
|
|
|
864
|
+
@dataclass
|
|
865
|
+
class StreamDeleteOptions:
|
|
866
|
+
"""Options for stream delete operations."""
|
|
867
|
+
|
|
868
|
+
namespace: str | None = None
|
|
869
|
+
force: bool = False # Delete even if the stream still has records
|
|
870
|
+
|
|
871
|
+
|
|
857
872
|
@dataclass
|
|
858
873
|
class StreamInfoOptions:
|
|
859
874
|
"""Options for stream info operations."""
|
|
@@ -904,17 +919,6 @@ class ActionType(IntEnum):
|
|
|
904
919
|
USER = 0 # External worker-based action
|
|
905
920
|
|
|
906
921
|
|
|
907
|
-
@dataclass
|
|
908
|
-
class ActionInfo:
|
|
909
|
-
"""Information about a registered action."""
|
|
910
|
-
|
|
911
|
-
name: str
|
|
912
|
-
action_type: ActionType
|
|
913
|
-
timeout_ms: int
|
|
914
|
-
max_retries: int
|
|
915
|
-
description: str | None = None
|
|
916
|
-
|
|
917
|
-
|
|
918
922
|
class RunStatus(IntEnum):
|
|
919
923
|
"""An action run's status."""
|
|
920
924
|
|
|
@@ -954,11 +958,16 @@ class ActionInvokeResult:
|
|
|
954
958
|
|
|
955
959
|
@dataclass
|
|
956
960
|
class ActionListResult:
|
|
957
|
-
"""
|
|
961
|
+
"""A page of registered action names. ``cursor`` gives the next page; None
|
|
962
|
+
on the last."""
|
|
958
963
|
|
|
959
|
-
|
|
964
|
+
names: list[str]
|
|
960
965
|
cursor: bytes | None = None
|
|
961
966
|
|
|
967
|
+
@property
|
|
968
|
+
def has_more(self) -> bool:
|
|
969
|
+
return self.cursor is not None
|
|
970
|
+
|
|
962
971
|
|
|
963
972
|
# =============================================================================
|
|
964
973
|
# Action Option Types
|
|
@@ -1005,11 +1014,13 @@ class ActionStatusOptions:
|
|
|
1005
1014
|
|
|
1006
1015
|
@dataclass
|
|
1007
1016
|
class ActionListOptions:
|
|
1008
|
-
"""Options for listing actions
|
|
1017
|
+
"""Options for listing actions: at most ``limit`` (1..1024; 0 is the
|
|
1018
|
+
server's default) after ``cursor``, the last page's cursor (None starts)."""
|
|
1009
1019
|
|
|
1010
1020
|
namespace: str | None = None
|
|
1011
1021
|
limit: int = 100
|
|
1012
1022
|
prefix: str | None = None
|
|
1023
|
+
cursor: bytes | None = None
|
|
1013
1024
|
|
|
1014
1025
|
|
|
1015
1026
|
@dataclass
|
|
@@ -1233,12 +1244,20 @@ class WorkflowHistoryOptions:
|
|
|
1233
1244
|
|
|
1234
1245
|
@dataclass
|
|
1235
1246
|
class WorkflowListRunsOptions:
|
|
1236
|
-
"""Options for listing workflow runs.
|
|
1247
|
+
"""Options for listing workflow runs.
|
|
1248
|
+
|
|
1249
|
+
``workflow_name`` None lists every workflow's runs. ``status`` and
|
|
1250
|
+
``search`` (a case-insensitive substring of the run's id, workflow, step,
|
|
1251
|
+
input or tags) narrow the list; None for any. ``cursor`` is the last
|
|
1252
|
+
page's, None to start. ``limit`` 0 asks for the server's default (100);
|
|
1253
|
+
the server sends at most 1024.
|
|
1254
|
+
"""
|
|
1237
1255
|
|
|
1238
1256
|
namespace: str | None = None
|
|
1239
1257
|
workflow_name: str | None = None
|
|
1240
|
-
|
|
1258
|
+
status: str | None = None
|
|
1241
1259
|
cursor: bytes | None = None
|
|
1260
|
+
search: str | None = None
|
|
1242
1261
|
limit: int = 100
|
|
1243
1262
|
|
|
1244
1263
|
|
|
@@ -1282,6 +1301,53 @@ class WorkflowSyncResult:
|
|
|
1282
1301
|
action: str # "created", "updated", "unchanged"
|
|
1283
1302
|
|
|
1284
1303
|
|
|
1304
|
+
@dataclass
|
|
1305
|
+
class WorkflowDefinitionEntry:
|
|
1306
|
+
"""A workflow definition as a definition list names it."""
|
|
1307
|
+
|
|
1308
|
+
name: str
|
|
1309
|
+
version: str
|
|
1310
|
+
created_at: int
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
@dataclass
|
|
1314
|
+
class WorkflowRunEntry:
|
|
1315
|
+
"""A workflow run as a run list names it. ``created_at`` is when the run
|
|
1316
|
+
started, in milliseconds since the epoch."""
|
|
1317
|
+
|
|
1318
|
+
run_id: str
|
|
1319
|
+
workflow: str
|
|
1320
|
+
status: str
|
|
1321
|
+
created_at: int
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
@dataclass
|
|
1325
|
+
class WorkflowListRunsResult:
|
|
1326
|
+
"""A page of workflow runs, newest first. ``cursor`` gives the next page;
|
|
1327
|
+
None on the last. A page may hold fewer than the limit and still have
|
|
1328
|
+
more."""
|
|
1329
|
+
|
|
1330
|
+
runs: list[WorkflowRunEntry]
|
|
1331
|
+
cursor: bytes | None = None
|
|
1332
|
+
|
|
1333
|
+
@property
|
|
1334
|
+
def has_more(self) -> bool:
|
|
1335
|
+
return self.cursor is not None
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
@dataclass
|
|
1339
|
+
class WorkflowListDefinitionsResult:
|
|
1340
|
+
"""A page of workflow definitions. ``cursor`` gives the next page; None on
|
|
1341
|
+
the last. A page may hold fewer than the limit and still have more."""
|
|
1342
|
+
|
|
1343
|
+
definitions: list[WorkflowDefinitionEntry]
|
|
1344
|
+
cursor: bytes | None = None
|
|
1345
|
+
|
|
1346
|
+
@property
|
|
1347
|
+
def has_more(self) -> bool:
|
|
1348
|
+
return self.cursor is not None
|
|
1349
|
+
|
|
1350
|
+
|
|
1285
1351
|
# =============================================================================
|
|
1286
1352
|
# Processing Types
|
|
1287
1353
|
# =============================================================================
|
|
@@ -1303,7 +1369,9 @@ class ProcessingStatusOptions:
|
|
|
1303
1369
|
|
|
1304
1370
|
@dataclass
|
|
1305
1371
|
class ProcessingListOptions:
|
|
1306
|
-
"""Options for listing processing jobs
|
|
1372
|
+
"""Options for listing processing jobs: at most ``limit`` (1..1024; 0 is
|
|
1373
|
+
the server's default) after ``cursor``, the last page's cursor (None
|
|
1374
|
+
starts)."""
|
|
1307
1375
|
|
|
1308
1376
|
namespace: str | None = None
|
|
1309
1377
|
limit: int = 100
|
|
@@ -1354,6 +1422,19 @@ class ProcessingListEntry:
|
|
|
1354
1422
|
created_at: int
|
|
1355
1423
|
|
|
1356
1424
|
|
|
1425
|
+
@dataclass
|
|
1426
|
+
class ProcessingListResult:
|
|
1427
|
+
"""A page of processing jobs. ``cursor`` gives the next page; None on the
|
|
1428
|
+
last."""
|
|
1429
|
+
|
|
1430
|
+
jobs: list[ProcessingListEntry]
|
|
1431
|
+
cursor: bytes | None = None
|
|
1432
|
+
|
|
1433
|
+
@property
|
|
1434
|
+
def has_more(self) -> bool:
|
|
1435
|
+
return self.cursor is not None
|
|
1436
|
+
|
|
1437
|
+
|
|
1357
1438
|
@dataclass
|
|
1358
1439
|
class ProcessingSyncResult:
|
|
1359
1440
|
"""Result of a processing sync operation."""
|
flo/wire.py
CHANGED
|
@@ -833,12 +833,13 @@ def serialize_action_invoke_value(
|
|
|
833
833
|
return b"\x01" + struct.pack("<H", len(labels_bytes)) + labels_bytes + input_data
|
|
834
834
|
|
|
835
835
|
|
|
836
|
-
def serialize_action_list_value(limit: int = 100) -> bytes:
|
|
836
|
+
def serialize_action_list_value(limit: int = 100, cursor: bytes | None = None) -> bytes:
|
|
837
837
|
"""Serialize action list value.
|
|
838
838
|
|
|
839
|
-
Format: [limit:u32][cursor...] (cursor omitted
|
|
839
|
+
Format: [limit:u32][cursor...] (cursor omitted on the first page; limit 0
|
|
840
|
+
is the server's default)
|
|
840
841
|
"""
|
|
841
|
-
return struct.pack("<I", limit)
|
|
842
|
+
return struct.pack("<I", limit) + (cursor or b"")
|
|
842
843
|
|
|
843
844
|
|
|
844
845
|
def serialize_worker_register_value(
|
flo/workflows.py
CHANGED
|
@@ -11,17 +11,22 @@ import re
|
|
|
11
11
|
import struct
|
|
12
12
|
from typing import TYPE_CHECKING, Any
|
|
13
13
|
|
|
14
|
+
from .exceptions import IncompleteResponseError, ValidationError
|
|
14
15
|
from .types import (
|
|
15
16
|
OpCode,
|
|
16
17
|
StatusCode,
|
|
17
18
|
WorkflowCancelOptions,
|
|
18
19
|
WorkflowCreateOptions,
|
|
20
|
+
WorkflowDefinitionEntry,
|
|
19
21
|
WorkflowDisableOptions,
|
|
20
22
|
WorkflowEnableOptions,
|
|
21
23
|
WorkflowGetDefinitionOptions,
|
|
22
24
|
WorkflowHistoryOptions,
|
|
23
25
|
WorkflowListDefinitionsOptions,
|
|
26
|
+
WorkflowListDefinitionsResult,
|
|
24
27
|
WorkflowListRunsOptions,
|
|
28
|
+
WorkflowListRunsResult,
|
|
29
|
+
WorkflowRunEntry,
|
|
25
30
|
WorkflowSignalOptions,
|
|
26
31
|
WorkflowStartOptions,
|
|
27
32
|
WorkflowStatusOptions,
|
|
@@ -62,7 +67,11 @@ class WorkflowOperations:
|
|
|
62
67
|
async def get_definition(
|
|
63
68
|
self, name: str, options: WorkflowGetDefinitionOptions | None = None
|
|
64
69
|
) -> str | None:
|
|
65
|
-
"""Get the YAML definition of a workflow. Returns None if not found.
|
|
70
|
+
"""Get the YAML definition of a workflow. Returns None if not found.
|
|
71
|
+
|
|
72
|
+
Raises:
|
|
73
|
+
NoNamespaceError: The namespace was never created.
|
|
74
|
+
"""
|
|
66
75
|
opts = options or WorkflowGetDefinitionOptions()
|
|
67
76
|
namespace = self._client.get_namespace(opts.namespace)
|
|
68
77
|
|
|
@@ -294,30 +303,42 @@ class WorkflowOperations:
|
|
|
294
303
|
namespace,
|
|
295
304
|
run_id.encode("utf-8"),
|
|
296
305
|
value,
|
|
297
|
-
allow_not_found=True,
|
|
298
306
|
)
|
|
299
307
|
|
|
300
308
|
return resp.data
|
|
301
309
|
|
|
302
|
-
async def list_runs(
|
|
303
|
-
|
|
310
|
+
async def list_runs(
|
|
311
|
+
self, options: WorkflowListRunsOptions | None = None
|
|
312
|
+
) -> WorkflowListRunsResult:
|
|
313
|
+
"""List one page of workflow runs, newest first.
|
|
314
|
+
|
|
315
|
+
Args:
|
|
316
|
+
options: The workflow (None for every workflow's runs), status and
|
|
317
|
+
search filters, limit, and cursor (the last page's ``cursor``;
|
|
318
|
+
None starts).
|
|
319
|
+
|
|
320
|
+
Returns:
|
|
321
|
+
WorkflowListRunsResult with the page's runs and the next page's
|
|
322
|
+
cursor, None on the last page. Page until ``has_more`` is False,
|
|
323
|
+
not until a page comes back short.
|
|
324
|
+
"""
|
|
304
325
|
opts = options or WorkflowListRunsOptions()
|
|
305
326
|
namespace = self._client.get_namespace(opts.namespace)
|
|
306
327
|
|
|
307
328
|
key = opts.workflow_name.encode("utf-8") if opts.workflow_name else b""
|
|
308
329
|
|
|
309
|
-
#
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
value = bytearray()
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
330
|
+
# [limit:u32][status_len:u16][status][cursor_len:u16][cursor]
|
|
331
|
+
# [search_len:u16][search], every field sent, an empty one as length 0.
|
|
332
|
+
if not 0 <= opts.limit <= 0xFFFFFFFF:
|
|
333
|
+
raise ValidationError(f"limit must be 0 to 4294967295, not {opts.limit}")
|
|
334
|
+
value = bytearray(struct.pack("<I", opts.limit))
|
|
335
|
+
for field in (
|
|
336
|
+
opts.status.encode("utf-8") if opts.status else b"",
|
|
337
|
+
opts.cursor or b"",
|
|
338
|
+
opts.search.encode("utf-8") if opts.search else b"",
|
|
339
|
+
):
|
|
340
|
+
value.extend(struct.pack("<H", len(field)))
|
|
341
|
+
value.extend(field)
|
|
321
342
|
|
|
322
343
|
resp = await self._client._send_and_check(
|
|
323
344
|
OpCode.WORKFLOW_LIST_RUNS,
|
|
@@ -325,19 +346,28 @@ class WorkflowOperations:
|
|
|
325
346
|
key,
|
|
326
347
|
bytes(value),
|
|
327
348
|
)
|
|
328
|
-
|
|
329
|
-
return
|
|
349
|
+
runs, cursor = _parse_run_list(resp.data)
|
|
350
|
+
return WorkflowListRunsResult(runs=runs, cursor=cursor)
|
|
330
351
|
|
|
331
352
|
async def list_definitions(
|
|
332
353
|
self, options: WorkflowListDefinitionsOptions | None = None
|
|
333
|
-
) ->
|
|
334
|
-
"""List
|
|
354
|
+
) -> WorkflowListDefinitionsResult:
|
|
355
|
+
"""List one page of workflow definitions.
|
|
356
|
+
|
|
357
|
+
Args:
|
|
358
|
+
options: The page's limit and cursor (the last page's ``cursor``;
|
|
359
|
+
None starts).
|
|
360
|
+
|
|
361
|
+
Returns:
|
|
362
|
+
WorkflowListDefinitionsResult with the page's definitions and the
|
|
363
|
+
next page's cursor, None on the last page. Page until ``has_more``
|
|
364
|
+
is False, not until a page comes back short.
|
|
365
|
+
"""
|
|
335
366
|
opts = options or WorkflowListDefinitionsOptions()
|
|
336
367
|
namespace = self._client.get_namespace(opts.namespace)
|
|
337
368
|
|
|
338
369
|
# Wire format: [limit:u32][cursor...]
|
|
339
|
-
|
|
340
|
-
value = struct.pack("<I", opts.limit) + cursor
|
|
370
|
+
value = struct.pack("<I", opts.limit) + (opts.cursor or b"")
|
|
341
371
|
|
|
342
372
|
resp = await self._client._send_and_check(
|
|
343
373
|
OpCode.WORKFLOW_LIST_DEFINITIONS,
|
|
@@ -345,8 +375,8 @@ class WorkflowOperations:
|
|
|
345
375
|
b"",
|
|
346
376
|
value,
|
|
347
377
|
)
|
|
348
|
-
|
|
349
|
-
return
|
|
378
|
+
entries, cursor = _parse_definition_list(resp.data)
|
|
379
|
+
return WorkflowListDefinitionsResult(definitions=entries, cursor=cursor)
|
|
350
380
|
|
|
351
381
|
async def disable(self, name: str, options: WorkflowDisableOptions | None = None) -> None:
|
|
352
382
|
"""Disable a workflow definition (prevents new runs)."""
|
|
@@ -435,6 +465,125 @@ class WorkflowOperations:
|
|
|
435
465
|
return results
|
|
436
466
|
|
|
437
467
|
|
|
468
|
+
# A page holds at most this many entries; a larger count is a corrupt answer.
|
|
469
|
+
_MAX_DEFINITION_LIST = 1024
|
|
470
|
+
_MAX_RUN_LIST = 1024
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _parse_run_list(data: bytes) -> tuple[list[WorkflowRunEntry], bytes | None]:
|
|
474
|
+
"""The page's runs and the next page's cursor, None on the last page.
|
|
475
|
+
|
|
476
|
+
Wire format: [count:u32]([run_id_len:u16][run_id][workflow_len:u16][workflow]
|
|
477
|
+
[status_len:u16][status][created_at:i64])*
|
|
478
|
+
[has_more:u8][cursor_len:u16][cursor]
|
|
479
|
+
"""
|
|
480
|
+
pos = 0
|
|
481
|
+
|
|
482
|
+
def take(n: int) -> bytes:
|
|
483
|
+
nonlocal pos
|
|
484
|
+
if pos + n > len(data):
|
|
485
|
+
raise IncompleteResponseError("workflow.list_runs answer is truncated")
|
|
486
|
+
b = data[pos : pos + n]
|
|
487
|
+
pos += n
|
|
488
|
+
return b
|
|
489
|
+
|
|
490
|
+
def read_str() -> str:
|
|
491
|
+
(n,) = struct.unpack("<H", take(2))
|
|
492
|
+
try:
|
|
493
|
+
return take(n).decode("utf-8")
|
|
494
|
+
except UnicodeDecodeError as e:
|
|
495
|
+
raise IncompleteResponseError(
|
|
496
|
+
"workflow.list_runs answer has a field that isn't UTF-8"
|
|
497
|
+
) from e
|
|
498
|
+
|
|
499
|
+
(count,) = struct.unpack("<I", take(4))
|
|
500
|
+
if count > _MAX_RUN_LIST:
|
|
501
|
+
raise IncompleteResponseError(f"workflow.list_runs answer lists {count} runs")
|
|
502
|
+
runs: list[WorkflowRunEntry] = []
|
|
503
|
+
for _ in range(count):
|
|
504
|
+
run_id = read_str()
|
|
505
|
+
workflow = read_str()
|
|
506
|
+
status = read_str()
|
|
507
|
+
(created_at,) = struct.unpack("<q", take(8))
|
|
508
|
+
runs.append(
|
|
509
|
+
WorkflowRunEntry(run_id=run_id, workflow=workflow, status=status, created_at=created_at)
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
has_more = take(1)[0]
|
|
513
|
+
if has_more > 1:
|
|
514
|
+
raise IncompleteResponseError(f"workflow.list_runs answer has a has_more of {has_more}")
|
|
515
|
+
(cursor_len,) = struct.unpack("<H", take(2))
|
|
516
|
+
cursor = take(cursor_len)
|
|
517
|
+
if pos != len(data):
|
|
518
|
+
raise IncompleteResponseError(
|
|
519
|
+
f"workflow.list_runs answer has {len(data) - pos} bytes after the cursor"
|
|
520
|
+
)
|
|
521
|
+
if has_more and not cursor:
|
|
522
|
+
raise IncompleteResponseError("workflow.list_runs answer has more pages but no cursor")
|
|
523
|
+
if not has_more and cursor:
|
|
524
|
+
raise IncompleteResponseError("workflow.list_runs answer has a cursor on its last page")
|
|
525
|
+
return runs, cursor if has_more else None
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def _parse_definition_list(
|
|
529
|
+
data: bytes,
|
|
530
|
+
) -> tuple[list[WorkflowDefinitionEntry], bytes | None]:
|
|
531
|
+
"""The page's definitions and the next page's cursor, None on the last page.
|
|
532
|
+
|
|
533
|
+
Wire format: [count:u32]([name_len:u16][name][version_len:u16][version]
|
|
534
|
+
[created_at:i64])*[has_more:u8][cursor_len:u16][cursor]
|
|
535
|
+
"""
|
|
536
|
+
pos = 0
|
|
537
|
+
|
|
538
|
+
def take(n: int) -> bytes:
|
|
539
|
+
nonlocal pos
|
|
540
|
+
if pos + n > len(data):
|
|
541
|
+
raise IncompleteResponseError("workflow.list_definitions answer is truncated")
|
|
542
|
+
b = data[pos : pos + n]
|
|
543
|
+
pos += n
|
|
544
|
+
return b
|
|
545
|
+
|
|
546
|
+
def read_str() -> str:
|
|
547
|
+
(n,) = struct.unpack("<H", take(2))
|
|
548
|
+
try:
|
|
549
|
+
return take(n).decode("utf-8")
|
|
550
|
+
except UnicodeDecodeError as e:
|
|
551
|
+
raise IncompleteResponseError(
|
|
552
|
+
"workflow.list_definitions answer has a field that isn't UTF-8"
|
|
553
|
+
) from e
|
|
554
|
+
|
|
555
|
+
(count,) = struct.unpack("<I", take(4))
|
|
556
|
+
if count > _MAX_DEFINITION_LIST:
|
|
557
|
+
raise IncompleteResponseError(f"workflow.list_definitions answer lists {count} definitions")
|
|
558
|
+
entries: list[WorkflowDefinitionEntry] = []
|
|
559
|
+
for _ in range(count):
|
|
560
|
+
name = read_str()
|
|
561
|
+
version = read_str()
|
|
562
|
+
(created_at,) = struct.unpack("<q", take(8))
|
|
563
|
+
entries.append(WorkflowDefinitionEntry(name=name, version=version, created_at=created_at))
|
|
564
|
+
|
|
565
|
+
has_more = take(1)[0]
|
|
566
|
+
if has_more > 1:
|
|
567
|
+
raise IncompleteResponseError(
|
|
568
|
+
f"workflow.list_definitions answer has a has_more of {has_more}"
|
|
569
|
+
)
|
|
570
|
+
(cursor_len,) = struct.unpack("<H", take(2))
|
|
571
|
+
cursor = take(cursor_len)
|
|
572
|
+
if pos != len(data):
|
|
573
|
+
raise IncompleteResponseError(
|
|
574
|
+
f"workflow.list_definitions answer has {len(data) - pos} bytes after the cursor"
|
|
575
|
+
)
|
|
576
|
+
if has_more and not cursor:
|
|
577
|
+
raise IncompleteResponseError(
|
|
578
|
+
"workflow.list_definitions answer has more pages but no cursor"
|
|
579
|
+
)
|
|
580
|
+
if not has_more and cursor:
|
|
581
|
+
raise IncompleteResponseError(
|
|
582
|
+
"workflow.list_definitions answer has a cursor on its last page"
|
|
583
|
+
)
|
|
584
|
+
return entries, cursor if has_more else None
|
|
585
|
+
|
|
586
|
+
|
|
438
587
|
# =============================================================================
|
|
439
588
|
# YAML Metadata Extraction (lightweight — no full parser needed)
|
|
440
589
|
# =============================================================================
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: flo-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Python SDK for the Flo distributed systems platform
|
|
5
5
|
Project-URL: Homepage, https://github.com/floruntime/flo-python
|
|
6
6
|
Project-URL: Documentation, https://github.com/floruntime/flo-python#readme
|
|
@@ -139,7 +139,7 @@ while True:
|
|
|
139
139
|
result = await client.kv.scan("user:", opts)
|
|
140
140
|
for name in result.names:
|
|
141
141
|
print(name)
|
|
142
|
-
if result.cursor is None
|
|
142
|
+
if result.cursor is None:
|
|
143
143
|
break
|
|
144
144
|
opts = ScanOptions(cursor=result.cursor, limit=100)
|
|
145
145
|
```
|
|
@@ -411,11 +411,19 @@ if status.error_message is not None:
|
|
|
411
411
|
```python
|
|
412
412
|
from flo import ActionListOptions
|
|
413
413
|
|
|
414
|
-
# List
|
|
415
|
-
|
|
414
|
+
# List the namespace's actions a page at a time
|
|
415
|
+
opts = ActionListOptions(limit=100)
|
|
416
|
+
while True:
|
|
417
|
+
page = await client.action.list(opts)
|
|
418
|
+
for name in page.names:
|
|
419
|
+
print(name)
|
|
420
|
+
if page.cursor is None:
|
|
421
|
+
break
|
|
422
|
+
opts = ActionListOptions(limit=100, cursor=page.cursor)
|
|
416
423
|
|
|
417
|
-
#
|
|
418
|
-
|
|
424
|
+
# Only actions whose names start with a prefix (needs the next server
|
|
425
|
+
# release; the current one lists every action)
|
|
426
|
+
page = await client.action.list(ActionListOptions(prefix="process-"))
|
|
419
427
|
|
|
420
428
|
# Delete an action
|
|
421
429
|
await client.action.delete("process-image")
|
|
@@ -456,7 +464,7 @@ while True:
|
|
|
456
464
|
page = await client.worker.list(opts)
|
|
457
465
|
for w in page.workers:
|
|
458
466
|
print(w.worker_id, w.status)
|
|
459
|
-
if page.cursor is None
|
|
467
|
+
if page.cursor is None:
|
|
460
468
|
break
|
|
461
469
|
opts = WorkerListOptions(limit=100, action="process-image", cursor=page.cursor)
|
|
462
470
|
```
|
|
@@ -619,6 +627,7 @@ A call that times out (`RequestTimeoutError`, also an `asyncio.TimeoutError`) or
|
|
|
619
627
|
| Error | Description |
|
|
620
628
|
|-------|-------------|
|
|
621
629
|
| `NotFoundError` | Key or resource not found |
|
|
630
|
+
| `NoNamespaceError` | Status `NO_NAMESPACE` (14), not a `NotFoundError`: a read, list or scan in a namespace that was never created (a write creates it) |
|
|
622
631
|
| `BadRequestError` | Invalid request parameters |
|
|
623
632
|
| `ConflictError` | CAS version mismatch |
|
|
624
633
|
| `UnauthorizedError` | Authentication failed |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
flo/__init__.py,sha256=8XB5g0YcQy5JfmVJKhUWGPBd-8cUWmH3isgOrNYwU0M,8582
|
|
2
|
+
flo/actions.py,sha256=tRJNFT76FK7fy-yRFnuP233FObn_6WDVK8QK_Tv3C2g,14214
|
|
3
|
+
flo/client.py,sha256=AIpSJ0xaE9bkNIeD-Hw698dGyt2yYRtcBhhBLfkV4D0,22484
|
|
4
|
+
flo/exceptions.py,sha256=aJy31guwKHlL-7woOEAzIPpPMBwDjcOACdo9l5s9kNw,9942
|
|
5
|
+
flo/kv.py,sha256=9OMTIWSEqHHcQ1_W6SOcBQNrNTwzlsma4rc_LKVFXnU,17631
|
|
6
|
+
flo/kv_body.py,sha256=JLk2VGWdXr4NnaqPjqZn8RPu8q3YaZKkx7plk1Bf_KE,21730
|
|
7
|
+
flo/kv_txn.py,sha256=FSo94kxrKzRiZyo69Pbx5DQICP4u_hvfSzNdgUUfEfE,8425
|
|
8
|
+
flo/processing.py,sha256=iO_S1WMfcRQ78I8zt-LgfC0tow6cxErM6Y8A9hxfEi8,10650
|
|
9
|
+
flo/queue.py,sha256=BoYekudiTAxB6PLpEft1j1sdW4A6rGB8A_MZZ15qjlw,8483
|
|
10
|
+
flo/retry.py,sha256=1cFInB1rnLAJbULUzxKO-PPfqG7MQUcl9gQcZdRxuyY,5491
|
|
11
|
+
flo/streams.py,sha256=wa-UnexIrI_23mUtHBXmRHQlvb5D5qbqnX0NKVWYQO8,18173
|
|
12
|
+
flo/types.py,sha256=8ksvL0j2Mn52Y_KPj9_SBflum3c9eg8PgFkUzekQdGk,39069
|
|
13
|
+
flo/wire.py,sha256=hlKrHvKtiaHP9ohmy9rX4ZCJ_AhFmTDIWwh3R8hQ5HU,34242
|
|
14
|
+
flo/worker.py,sha256=vkDWeK7syPOjehdcWZgxQBLsxv7emc3SURyBRwI4mi0,71569
|
|
15
|
+
flo/workflows.py,sha256=Ein3dhUFhSBBfU4wDCSuB_ThmGetY5IkAl4QctsBL7M,20642
|
|
16
|
+
flo_python-0.1.4.dist-info/METADATA,sha256=mUJeQ1B75566_TGcAPxGPPH-NRsztT8srlnSNDO_N98,25012
|
|
17
|
+
flo_python-0.1.4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
18
|
+
flo_python-0.1.4.dist-info/licenses/LICENSE,sha256=ti77D_daMo24gEINF1J7388qriJ5r5GjuJUo0b0k27o,11344
|
|
19
|
+
flo_python-0.1.4.dist-info/RECORD,,
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
flo/__init__.py,sha256=stUt6r258QiNRxx-xhM1yQuTGTvZyGbdv_CcW8LOkvg,8228
|
|
2
|
-
flo/actions.py,sha256=bDJ5j69M8l7wi5TxOS5xHAz9k2ln2eEkoBU7GPuiWoo,14008
|
|
3
|
-
flo/client.py,sha256=AIpSJ0xaE9bkNIeD-Hw698dGyt2yYRtcBhhBLfkV4D0,22484
|
|
4
|
-
flo/exceptions.py,sha256=MvRpUWcgumDWmvbF-7fXDGYOk-rI6Ft2-59vnbwz9pE,9552
|
|
5
|
-
flo/kv.py,sha256=G5HVDhw4mtjs7gYZiLbjVs9O1_IfGJ_ePf2DT_LM_aw,17588
|
|
6
|
-
flo/kv_body.py,sha256=YtonXKZKuPyUecPSmxXwscUJVCEdBZQZ7NY4TIP8Muo,20623
|
|
7
|
-
flo/kv_txn.py,sha256=FSo94kxrKzRiZyo69Pbx5DQICP4u_hvfSzNdgUUfEfE,8425
|
|
8
|
-
flo/processing.py,sha256=0hjWvYpAg_mugM8XQq81TrE1uF3POPNVH2KE-oe9V6E,9032
|
|
9
|
-
flo/queue.py,sha256=BoYekudiTAxB6PLpEft1j1sdW4A6rGB8A_MZZ15qjlw,8483
|
|
10
|
-
flo/retry.py,sha256=1cFInB1rnLAJbULUzxKO-PPfqG7MQUcl9gQcZdRxuyY,5491
|
|
11
|
-
flo/streams.py,sha256=RIdZIyww-1FXjJpDNfw_sBhjXjgScqt1EZEsXmE6TXc,17444
|
|
12
|
-
flo/types.py,sha256=lgfeROaQVjOf4vNpPtXpa3LA5p6VP3QgAWv9fqh9GjU,36552
|
|
13
|
-
flo/wire.py,sha256=q3wKGZLvi2zN7XFSGegOecO3J6sfkZZtCwYpUx6Mt-w,34149
|
|
14
|
-
flo/worker.py,sha256=vkDWeK7syPOjehdcWZgxQBLsxv7emc3SURyBRwI4mi0,71569
|
|
15
|
-
flo/workflows.py,sha256=8Z5mhq2UOAnjV_Ef261mcWlj4Z5yGCwrFbxjey0ICoU,15050
|
|
16
|
-
flo_python-0.1.3.dist-info/METADATA,sha256=_W2CHFBxXCrd_7mGIOGdtyU2H4AXyF9DE_mG5T320xg,24576
|
|
17
|
-
flo_python-0.1.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
18
|
-
flo_python-0.1.3.dist-info/licenses/LICENSE,sha256=ti77D_daMo24gEINF1J7388qriJ5r5GjuJUo0b0k27o,11344
|
|
19
|
-
flo_python-0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|