flo-python 0.1.5__py3-none-any.whl → 0.1.7__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 +63 -1
- flo/client.py +2 -0
- flo/exceptions.py +26 -7
- flo/kv.py +5 -14
- flo/kv_body.py +266 -2
- flo/processing.py +16 -3
- flo/queue.py +67 -72
- flo/retry.py +13 -0
- flo/streams.py +200 -1
- flo/ts.py +465 -0
- flo/types.py +397 -29
- flo/wire.py +7 -3
- flo/worker.py +103 -21
- {flo_python-0.1.5.dist-info → flo_python-0.1.7.dist-info}/METADATA +230 -9
- flo_python-0.1.7.dist-info/RECORD +20 -0
- flo_python-0.1.5.dist-info/RECORD +0 -19
- {flo_python-0.1.5.dist-info → flo_python-0.1.7.dist-info}/WHEEL +0 -0
- {flo_python-0.1.5.dist-info → flo_python-0.1.7.dist-info}/licenses/LICENSE +0 -0
flo/__init__.py
CHANGED
|
@@ -73,6 +73,7 @@ from .exceptions import (
|
|
|
73
73
|
from .kv_txn import Transaction, TxnFinishedError, TxnUnsupportedOpError
|
|
74
74
|
from .processing import ProcessingOperations
|
|
75
75
|
from .retry import DEFAULT_RETRY_POLICY, RetryPolicy
|
|
76
|
+
from .ts import TSOperations
|
|
76
77
|
from .types import (
|
|
77
78
|
ActionDeleteOptions,
|
|
78
79
|
ActionInfo,
|
|
@@ -90,18 +91,32 @@ from .types import (
|
|
|
90
91
|
DeleteOptions,
|
|
91
92
|
DequeueOptions,
|
|
92
93
|
DequeueResult,
|
|
94
|
+
DlqCursor,
|
|
95
|
+
DlqDeleteOptions,
|
|
93
96
|
DlqListOptions,
|
|
94
97
|
DlqPage,
|
|
98
|
+
DlqRequeueOptions,
|
|
99
|
+
DlqResult,
|
|
95
100
|
EnqueueOptions,
|
|
96
101
|
ExistsResult,
|
|
102
|
+
FloQLPoint,
|
|
103
|
+
FloQLSeries,
|
|
97
104
|
GetJsonResult,
|
|
98
105
|
GetOptions,
|
|
99
106
|
GetResult,
|
|
107
|
+
GroupDeadLetter,
|
|
108
|
+
GroupDlqCursor,
|
|
109
|
+
GroupDlqDeleteOptions,
|
|
110
|
+
GroupDlqListOptions,
|
|
111
|
+
GroupDlqPage,
|
|
112
|
+
GroupDlqRequeueOptions,
|
|
113
|
+
GroupDlqResult,
|
|
100
114
|
GroupMemberState,
|
|
101
115
|
GroupReadResult,
|
|
102
116
|
GroupRecord,
|
|
103
117
|
GroupRefusal,
|
|
104
118
|
GroupReportResult,
|
|
119
|
+
GroupStealResult,
|
|
105
120
|
GroupTouchResult,
|
|
106
121
|
HistoryOptions,
|
|
107
122
|
HistoryResult,
|
|
@@ -150,8 +165,10 @@ from .types import (
|
|
|
150
165
|
ScanResult,
|
|
151
166
|
StatusCode,
|
|
152
167
|
StorageTier,
|
|
168
|
+
StreamAlterOptions,
|
|
153
169
|
StreamAppendOptions,
|
|
154
170
|
StreamAppendResult,
|
|
171
|
+
StreamCreateOptions,
|
|
155
172
|
StreamDeleteOptions,
|
|
156
173
|
StreamGroupAckOptions,
|
|
157
174
|
StreamGroupCreateOptions,
|
|
@@ -162,6 +179,7 @@ from .types import (
|
|
|
162
179
|
StreamGroupMembersResult,
|
|
163
180
|
StreamGroupNackOptions,
|
|
164
181
|
StreamGroupReadOptions,
|
|
182
|
+
StreamGroupStealOptions,
|
|
165
183
|
StreamID,
|
|
166
184
|
StreamInfo,
|
|
167
185
|
StreamInfoOptions,
|
|
@@ -171,6 +189,16 @@ from .types import (
|
|
|
171
189
|
StreamTrimOptions,
|
|
172
190
|
StreamTrimResult,
|
|
173
191
|
TaskAssignment,
|
|
192
|
+
TSAggregation,
|
|
193
|
+
TSBucket,
|
|
194
|
+
TSInfo,
|
|
195
|
+
TSOrder,
|
|
196
|
+
TSPoint,
|
|
197
|
+
TSQueryOptions,
|
|
198
|
+
TSReadOptions,
|
|
199
|
+
TSReadResult,
|
|
200
|
+
TSWriteOptions,
|
|
201
|
+
TSWriteResult,
|
|
174
202
|
VersionEntry,
|
|
175
203
|
WaitFor,
|
|
176
204
|
WorkerAwaitOptions,
|
|
@@ -202,6 +230,9 @@ from .types import (
|
|
|
202
230
|
WorkflowStatusOptions,
|
|
203
231
|
WorkflowSyncOptions,
|
|
204
232
|
WorkflowSyncResult,
|
|
233
|
+
datetime_from_ns,
|
|
234
|
+
ns_from_datetime,
|
|
235
|
+
ns_from_timedelta,
|
|
205
236
|
)
|
|
206
237
|
from .worker import (
|
|
207
238
|
ActionContext,
|
|
@@ -215,7 +246,7 @@ from .worker import (
|
|
|
215
246
|
)
|
|
216
247
|
from .workflows import WorkflowOperations
|
|
217
248
|
|
|
218
|
-
__version__ = "0.1.
|
|
249
|
+
__version__ = "0.1.7"
|
|
219
250
|
|
|
220
251
|
__all__ = [
|
|
221
252
|
"Transaction",
|
|
@@ -309,6 +340,21 @@ __all__ = [
|
|
|
309
340
|
"HistoryOptions",
|
|
310
341
|
"EnqueueOptions",
|
|
311
342
|
"DequeueOptions",
|
|
343
|
+
"DlqCursor",
|
|
344
|
+
"DlqResult",
|
|
345
|
+
"DlqRequeueOptions",
|
|
346
|
+
"DlqDeleteOptions",
|
|
347
|
+
"GroupStealResult",
|
|
348
|
+
"GroupDeadLetter",
|
|
349
|
+
"GroupDlqCursor",
|
|
350
|
+
"GroupDlqPage",
|
|
351
|
+
"GroupDlqResult",
|
|
352
|
+
"StreamCreateOptions",
|
|
353
|
+
"StreamAlterOptions",
|
|
354
|
+
"StreamGroupStealOptions",
|
|
355
|
+
"GroupDlqListOptions",
|
|
356
|
+
"GroupDlqRequeueOptions",
|
|
357
|
+
"GroupDlqDeleteOptions",
|
|
312
358
|
"DlqListOptions",
|
|
313
359
|
"DlqPage",
|
|
314
360
|
"PeekOptions",
|
|
@@ -413,5 +459,21 @@ __all__ = [
|
|
|
413
459
|
"ProcessingListResult",
|
|
414
460
|
"ProcessingRemoveOptions",
|
|
415
461
|
"ProcessingRuntime",
|
|
462
|
+
"FloQLPoint",
|
|
463
|
+
"FloQLSeries",
|
|
464
|
+
"TSOrder",
|
|
465
|
+
"TSAggregation",
|
|
466
|
+
"TSBucket",
|
|
467
|
+
"TSInfo",
|
|
468
|
+
"TSQueryOptions",
|
|
469
|
+
"ns_from_timedelta",
|
|
470
|
+
"TSPoint",
|
|
471
|
+
"TSReadOptions",
|
|
472
|
+
"TSReadResult",
|
|
473
|
+
"TSWriteOptions",
|
|
474
|
+
"TSWriteResult",
|
|
475
|
+
"datetime_from_ns",
|
|
476
|
+
"ns_from_datetime",
|
|
477
|
+
"TSOperations",
|
|
416
478
|
"ProcessingSyncResult",
|
|
417
479
|
]
|
flo/client.py
CHANGED
|
@@ -114,6 +114,7 @@ class FloClient:
|
|
|
114
114
|
from .processing import ProcessingOperations
|
|
115
115
|
from .queue import QueueOperations
|
|
116
116
|
from .streams import StreamOperations
|
|
117
|
+
from .ts import TSOperations
|
|
117
118
|
from .workflows import WorkflowOperations
|
|
118
119
|
|
|
119
120
|
self.kv = KVOperations(self)
|
|
@@ -123,6 +124,7 @@ class FloClient:
|
|
|
123
124
|
self.worker = WorkerOperations(self)
|
|
124
125
|
self.workflow = WorkflowOperations(self)
|
|
125
126
|
self.processing = ProcessingOperations(self)
|
|
127
|
+
self.ts = TSOperations(self)
|
|
126
128
|
|
|
127
129
|
if debug:
|
|
128
130
|
logging.basicConfig(level=logging.DEBUG)
|
flo/exceptions.py
CHANGED
|
@@ -183,10 +183,12 @@ class NotFoundError(ServerError):
|
|
|
183
183
|
|
|
184
184
|
|
|
185
185
|
class StaleNotFoundError(NotFoundError):
|
|
186
|
-
"""A
|
|
187
|
-
|
|
188
|
-
that
|
|
189
|
-
|
|
186
|
+
"""A node answered not found from state it knows may be behind (``stale``
|
|
187
|
+
is True): a halted or read-blocked shard, as of the entry it couldn't
|
|
188
|
+
apply, or a follower that couldn't reach the leader. It may exist: read
|
|
189
|
+
again rather than treat it as gone. kv.get and kv.json_get raise it
|
|
190
|
+
rather than report the key absent; stream.read, ts.read and
|
|
191
|
+
ts.iter_points raise it for the stream or series."""
|
|
190
192
|
|
|
191
193
|
stale = True
|
|
192
194
|
|
|
@@ -250,9 +252,10 @@ class GroupHeldFullError(OverloadedError):
|
|
|
250
252
|
names which cap. At the group's cap (records ready, leased and dead
|
|
251
253
|
together), acks and nacks make room, but dead records stay until the
|
|
252
254
|
group is deleted or a trim of the stream cuts them. At the shard's cap
|
|
253
|
-
(its queues and groups together),
|
|
254
|
-
|
|
255
|
-
it; a stream worker logs it and
|
|
255
|
+
(its queues and groups together), this group's own acks free room, as do
|
|
256
|
+
other groups and queues on the shard draining. Reading again won't help
|
|
257
|
+
until then, so the client never retries it; a stream worker logs it and
|
|
258
|
+
backs off."""
|
|
256
259
|
|
|
257
260
|
|
|
258
261
|
class RateLimitedError(ServerError):
|
|
@@ -329,6 +332,22 @@ def is_connection_error(exc: BaseException) -> bool:
|
|
|
329
332
|
return isinstance(exc, (UnexpectedEofError, NotConnectedError, RequestTimeoutError, OSError))
|
|
330
333
|
|
|
331
334
|
|
|
335
|
+
def not_found_error(status: StatusCode, data: bytes, stale: bool) -> ServerError:
|
|
336
|
+
"""The error a not-found answer raises. On a stale answer, a thing not
|
|
337
|
+
found (reason NOT_FOUND) is a StaleNotFoundError: the node hadn't seen it
|
|
338
|
+
yet, so it may exist."""
|
|
339
|
+
try:
|
|
340
|
+
raise_for_status(status, data)
|
|
341
|
+
except ServerError as e:
|
|
342
|
+
e.stale = stale
|
|
343
|
+
if stale and e.reason == Reason.NOT_FOUND:
|
|
344
|
+
found = StaleNotFoundError(str(e))
|
|
345
|
+
found.reason, found.ran = e.reason, e.ran
|
|
346
|
+
return found
|
|
347
|
+
return e
|
|
348
|
+
raise AssertionError("a not-found answer always raises") # pragma: no cover
|
|
349
|
+
|
|
350
|
+
|
|
332
351
|
def raise_for_status(status: StatusCode, data: bytes = b"") -> None:
|
|
333
352
|
"""Raise appropriate exception for non-OK status codes.
|
|
334
353
|
|
flo/kv.py
CHANGED
|
@@ -8,9 +8,8 @@ from typing import TYPE_CHECKING, Any
|
|
|
8
8
|
|
|
9
9
|
from .exceptions import (
|
|
10
10
|
IncompleteResponseError,
|
|
11
|
-
ServerError,
|
|
12
11
|
StaleNotFoundError,
|
|
13
|
-
|
|
12
|
+
not_found_error,
|
|
14
13
|
)
|
|
15
14
|
from .kv_body import (
|
|
16
15
|
decode_delete_answer,
|
|
@@ -79,18 +78,10 @@ def _absent(response: RawResponse, *, stale_raises: bool = False) -> bool:
|
|
|
79
78
|
absent."""
|
|
80
79
|
if not response.is_not_found():
|
|
81
80
|
return False
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if e.reason != Reason.NOT_FOUND:
|
|
87
|
-
raise
|
|
88
|
-
if stale_raises and response.stale:
|
|
89
|
-
stale = StaleNotFoundError(str(e))
|
|
90
|
-
stale.reason, stale.ran = e.reason, e.ran
|
|
91
|
-
raise stale from None
|
|
92
|
-
return True
|
|
93
|
-
return False # pragma: no cover - raise_for_status always raises here
|
|
81
|
+
e = not_found_error(response.status, response.data, response.stale)
|
|
82
|
+
if e.reason != Reason.NOT_FOUND or (stale_raises and isinstance(e, StaleNotFoundError)):
|
|
83
|
+
raise e
|
|
84
|
+
return True
|
|
94
85
|
|
|
95
86
|
|
|
96
87
|
async def kv_get(
|
flo/kv_body.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""The ops on the server's op table: KV, the action reports and reads,
|
|
2
2
|
worker.list and worker.info, stream group reads, the queue's dequeue,
|
|
3
|
-
reports and peek, and processing.remove.
|
|
3
|
+
reports and peek, ts.read and ts.info, and processing.remove.
|
|
4
4
|
|
|
5
5
|
The request is ``[namespace][key][body]``, the body coded by the op's
|
|
6
6
|
schema, field by field in order. An optional field is a presence byte then
|
|
@@ -22,11 +22,22 @@ from .types import (
|
|
|
22
22
|
ActionListEntry,
|
|
23
23
|
ActionRunStatus,
|
|
24
24
|
Condition,
|
|
25
|
+
DeadLetter,
|
|
25
26
|
DequeueResult,
|
|
27
|
+
DlqCursor,
|
|
28
|
+
DlqPage,
|
|
29
|
+
DlqResult,
|
|
26
30
|
ExistsResult,
|
|
27
31
|
GetOptions,
|
|
28
32
|
GetResult,
|
|
33
|
+
GroupDeadLetter,
|
|
34
|
+
GroupDlqCursor,
|
|
35
|
+
GroupDlqPage,
|
|
36
|
+
GroupDlqResult,
|
|
29
37
|
GroupMemberState,
|
|
38
|
+
GroupRecord,
|
|
39
|
+
GroupRefusal,
|
|
40
|
+
GroupStealResult,
|
|
30
41
|
Message,
|
|
31
42
|
MGetEntry,
|
|
32
43
|
OpCode,
|
|
@@ -44,6 +55,7 @@ from .types import (
|
|
|
44
55
|
StreamGroupListResult,
|
|
45
56
|
StreamGroupMember,
|
|
46
57
|
StreamGroupMembersResult,
|
|
58
|
+
StreamID,
|
|
47
59
|
TaskAssignment,
|
|
48
60
|
VersionEntry,
|
|
49
61
|
WaitFor,
|
|
@@ -85,6 +97,12 @@ MAX_CONSUMER = 4082
|
|
|
85
97
|
MIN_LEASE_MS = 5_000
|
|
86
98
|
MAX_LEASE_MS = 43_200_000
|
|
87
99
|
MAX_QUEUE_ERROR = 1024
|
|
100
|
+
# The most records or messages a steal, or a dead letter requeue or delete,
|
|
101
|
+
# names, and the most dead letters one page lists.
|
|
102
|
+
MAX_DEAD_BATCH = 100
|
|
103
|
+
MAX_DLQ_PAGE = 100
|
|
104
|
+
# A steal's idle time: up to the longest lease.
|
|
105
|
+
MAX_MIN_IDLE_MS = 43_200_000
|
|
88
106
|
# The longest TTL whose nanoseconds fit a u64.
|
|
89
107
|
MAX_TTL_MS = 18_446_744_073_709
|
|
90
108
|
_U64_MAX = (1 << 64) - 1
|
|
@@ -118,11 +136,19 @@ _TABLE_OPS = frozenset(
|
|
|
118
136
|
OpCode.WORKER_INFO,
|
|
119
137
|
OpCode.STREAM_GROUP_LIST,
|
|
120
138
|
OpCode.STREAM_GROUP_MEMBERS,
|
|
139
|
+
OpCode.STREAM_GROUP_STEAL,
|
|
140
|
+
OpCode.STREAM_GROUP_DLQ_LIST,
|
|
141
|
+
OpCode.STREAM_GROUP_DLQ_REQUEUE,
|
|
142
|
+
OpCode.STREAM_GROUP_DLQ_DELETE,
|
|
121
143
|
OpCode.QUEUE_PEEK,
|
|
122
144
|
OpCode.QUEUE_DEQUEUE,
|
|
123
145
|
OpCode.QUEUE_COMPLETE,
|
|
124
146
|
OpCode.QUEUE_FAIL,
|
|
125
147
|
OpCode.QUEUE_TOUCH,
|
|
148
|
+
OpCode.QUEUE_DLQ_LIST,
|
|
149
|
+
OpCode.QUEUE_DLQ_REQUEUE,
|
|
150
|
+
OpCode.QUEUE_DLQ_DELETE,
|
|
151
|
+
OpCode.TS_READ,
|
|
126
152
|
OpCode.TS_INFO,
|
|
127
153
|
OpCode.PROCESSING_REMOVE,
|
|
128
154
|
}
|
|
@@ -504,6 +530,124 @@ def encode_peek_body(limit: int) -> bytes:
|
|
|
504
530
|
return _limit("peek limit", limit, MAX_PEEK)
|
|
505
531
|
|
|
506
532
|
|
|
533
|
+
def _dead_pick(names: str, count: int, all_: bool, limit: int) -> None:
|
|
534
|
+
"""A dead letter requeue or delete names some, or takes all: not both,
|
|
535
|
+
nor neither."""
|
|
536
|
+
if all_ == (count > 0):
|
|
537
|
+
raise ValidationError(
|
|
538
|
+
f"name the dead letters ({names}) or give all, not both"
|
|
539
|
+
if all_
|
|
540
|
+
else f"name the dead letters ({names}), or give all"
|
|
541
|
+
)
|
|
542
|
+
if count > MAX_DEAD_BATCH:
|
|
543
|
+
raise ValidationError(f"a batch names at most {MAX_DEAD_BATCH} {names}, got {count}")
|
|
544
|
+
_limit("limit", limit, MAX_DEAD_BATCH)
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
def encode_queue_dlq_list_body(limit: int, after: DlqCursor | None) -> bytes:
|
|
548
|
+
"""queue.dlq_list's request: limit, after?."""
|
|
549
|
+
body = _limit("dlq list limit", limit, MAX_DLQ_PAGE)
|
|
550
|
+
if after is None:
|
|
551
|
+
return body + b"\x00"
|
|
552
|
+
return body + b"\x01" + _u64("cursor", after.dead_ns) + _u64("cursor", after.seq)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def encode_queue_dlq_body(
|
|
556
|
+
seqs: Sequence[int] | None, all_: bool, limit: int, dry_run: bool | None = None
|
|
557
|
+
) -> bytes:
|
|
558
|
+
"""queue.dlq_requeue's request: messages?, all, limit; queue.dlq_delete's
|
|
559
|
+
adds dry_run (``dry_run`` not None)."""
|
|
560
|
+
picked = list(seqs or [])
|
|
561
|
+
_dead_pick("messages", len(picked), all_, limit)
|
|
562
|
+
body = (
|
|
563
|
+
(b"\x01" + bytes([len(picked)]) + b"".join(_u64("seq", q) for q in picked))
|
|
564
|
+
if picked
|
|
565
|
+
else b"\x00"
|
|
566
|
+
)
|
|
567
|
+
body += b"\x01" + _flag(all_) + _limit("limit", limit, MAX_DEAD_BATCH)
|
|
568
|
+
if dry_run is not None:
|
|
569
|
+
body += b"\x01" + _flag(dry_run)
|
|
570
|
+
return body
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def _record_id(r: StreamID) -> bytes:
|
|
574
|
+
return _u64("record ms", r.timestamp_ms) + _u64("record seq", r.sequence)
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
def encode_group_steal_body(
|
|
578
|
+
group: str,
|
|
579
|
+
consumer: str,
|
|
580
|
+
min_idle_ms: int,
|
|
581
|
+
lease_ms: int | None,
|
|
582
|
+
records: Sequence[tuple[StreamID, int]],
|
|
583
|
+
) -> bytes:
|
|
584
|
+
"""stream.group.steal's request: group, consumer, min_idle_ms, lease_ms?,
|
|
585
|
+
records (each id and the deliveries its holder has)."""
|
|
586
|
+
if not consumer:
|
|
587
|
+
raise ValidationError("a steal names the consumer that takes the records")
|
|
588
|
+
if (
|
|
589
|
+
not isinstance(min_idle_ms, int)
|
|
590
|
+
or isinstance(min_idle_ms, bool)
|
|
591
|
+
or not 1 <= min_idle_ms <= MAX_MIN_IDLE_MS
|
|
592
|
+
):
|
|
593
|
+
raise ValidationError(f"min_idle_ms must be 1..{MAX_MIN_IDLE_MS}, got {min_idle_ms!r}")
|
|
594
|
+
if lease_ms is not None and (
|
|
595
|
+
not isinstance(lease_ms, int)
|
|
596
|
+
or isinstance(lease_ms, bool)
|
|
597
|
+
or not MIN_LEASE_MS <= lease_ms <= MAX_LEASE_MS
|
|
598
|
+
):
|
|
599
|
+
raise ValidationError(f"lease_ms must be {MIN_LEASE_MS}..{MAX_LEASE_MS}, got {lease_ms!r}")
|
|
600
|
+
if not 1 <= len(records) <= MAX_DEAD_BATCH:
|
|
601
|
+
raise ValidationError(f"a steal names 1..{MAX_DEAD_BATCH} records, got {len(records)}")
|
|
602
|
+
return (
|
|
603
|
+
_bytes16("group", group.encode("utf-8"), _MAX_KEY)
|
|
604
|
+
+ _bytes16("consumer", consumer.encode("utf-8"), _MAX_KEY)
|
|
605
|
+
+ _u64("min_idle_ms", min_idle_ms)
|
|
606
|
+
+ _opt_u64("lease_ms", lease_ms)
|
|
607
|
+
+ bytes([len(records)])
|
|
608
|
+
+ b"".join(_record_id(rid) + _u32("deliveries", d) for rid, d in records)
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def encode_group_dlq_list_body(group: str, limit: int, after: GroupDlqCursor | None) -> bytes:
|
|
613
|
+
"""stream.group.dlq_list's request: group, limit, after?."""
|
|
614
|
+
body = _bytes16("group", group.encode("utf-8"), _MAX_KEY) + _limit(
|
|
615
|
+
"dlq list limit", limit, MAX_DLQ_PAGE
|
|
616
|
+
)
|
|
617
|
+
if after is None:
|
|
618
|
+
return body + b"\x00"
|
|
619
|
+
return (
|
|
620
|
+
body
|
|
621
|
+
+ b"\x01"
|
|
622
|
+
+ _u64("cursor", after.dead_ns)
|
|
623
|
+
+ _u64("cursor", after.ms)
|
|
624
|
+
+ _u64("cursor", after.seq)
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def encode_group_dlq_body(
|
|
629
|
+
group: str,
|
|
630
|
+
records: Sequence[StreamID] | None,
|
|
631
|
+
all_: bool,
|
|
632
|
+
limit: int,
|
|
633
|
+
dry_run: bool | None = None,
|
|
634
|
+
) -> bytes:
|
|
635
|
+
"""stream.group.dlq_requeue's request: group, records?, all, limit;
|
|
636
|
+
stream.group.dlq_delete's adds dry_run (``dry_run`` not None)."""
|
|
637
|
+
picked = list(records or [])
|
|
638
|
+
_dead_pick("records", len(picked), all_, limit)
|
|
639
|
+
body = _bytes16("group", group.encode("utf-8"), _MAX_KEY)
|
|
640
|
+
body += (
|
|
641
|
+
(b"\x01" + bytes([len(picked)]) + b"".join(_record_id(r) for r in picked))
|
|
642
|
+
if picked
|
|
643
|
+
else b"\x00"
|
|
644
|
+
)
|
|
645
|
+
body += b"\x01" + _flag(all_) + _limit("limit", limit, MAX_DEAD_BATCH)
|
|
646
|
+
if dry_run is not None:
|
|
647
|
+
body += b"\x01" + _flag(dry_run)
|
|
648
|
+
return body
|
|
649
|
+
|
|
650
|
+
|
|
507
651
|
# ── Answers ───────────────────────────────────────────────────────────────
|
|
508
652
|
|
|
509
653
|
|
|
@@ -712,7 +856,8 @@ def _text(a: _Answer, op: str, raw: bytes) -> str:
|
|
|
712
856
|
|
|
713
857
|
def decode_action_status_answer(run_id: str, data: bytes) -> ActionRunStatus:
|
|
714
858
|
"""action.status's answer: status, created_at, started_at?, completed_at?,
|
|
715
|
-
attempt, output?, error_message?, worker_id?, outcome
|
|
859
|
+
attempt, output?, error_message?, worker_id?, outcome? (u16 lengths),
|
|
860
|
+
held? (a u8 length)."""
|
|
716
861
|
a = _Answer("action.status", data)
|
|
717
862
|
code = a.u8()
|
|
718
863
|
try:
|
|
@@ -729,6 +874,7 @@ def decode_action_status_answer(run_id: str, data: bytes) -> ActionRunStatus:
|
|
|
729
874
|
error = a.bytes16() if a.present() else None
|
|
730
875
|
worker_id = a.bytes16() if a.present() else None
|
|
731
876
|
outcome = a.bytes16() if a.present() else None
|
|
877
|
+
held = a.bytes8() if a.present() else None
|
|
732
878
|
a.done()
|
|
733
879
|
return ActionRunStatus(
|
|
734
880
|
run_id=run_id,
|
|
@@ -741,6 +887,7 @@ def decode_action_status_answer(run_id: str, data: bytes) -> ActionRunStatus:
|
|
|
741
887
|
error_message=error.decode("utf-8", errors="replace") if error is not None else None,
|
|
742
888
|
worker_id=worker_id.decode("utf-8", errors="replace") if worker_id is not None else None,
|
|
743
889
|
outcome=outcome.decode("utf-8", errors="replace") if outcome is not None else None,
|
|
890
|
+
held=held.decode("utf-8", errors="replace") if held is not None else None,
|
|
744
891
|
)
|
|
745
892
|
|
|
746
893
|
|
|
@@ -1063,3 +1210,120 @@ def decode_queue_touch_answer(data: bytes) -> QueueTouchResult:
|
|
|
1063
1210
|
refused = _refusals(a, op)
|
|
1064
1211
|
a.done()
|
|
1065
1212
|
return QueueTouchResult(expires_at_ms=expires_at_ms, applied=applied, refused=refused)
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
def _why(a: _Answer, op: str) -> QueueRefusalReason:
|
|
1216
|
+
code = a.u8()
|
|
1217
|
+
try:
|
|
1218
|
+
return QueueRefusalReason(code)
|
|
1219
|
+
except ValueError:
|
|
1220
|
+
raise IncompleteResponseError(f"{op} answer has an unknown refusal {code}") from None
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
def _group_refusals(a: _Answer, op: str) -> list[GroupRefusal]:
|
|
1224
|
+
refused = []
|
|
1225
|
+
for _ in range(a.u8()):
|
|
1226
|
+
ms, seq = a.u64(), a.u64()
|
|
1227
|
+
why = _why(a, op)
|
|
1228
|
+
refused.append(
|
|
1229
|
+
GroupRefusal(
|
|
1230
|
+
id=StreamID(timestamp_ms=ms, sequence=seq),
|
|
1231
|
+
why=why,
|
|
1232
|
+
reason=_text(a, op, a.bytes8()),
|
|
1233
|
+
)
|
|
1234
|
+
)
|
|
1235
|
+
return refused
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
def decode_group_steal_answer(data: bytes, consumer: str) -> GroupStealResult:
|
|
1239
|
+
"""stream.group.steal's answer: term, index, expires_at_ms, stolen (each
|
|
1240
|
+
id and new deliveries), refused."""
|
|
1241
|
+
op = "stream.group.steal"
|
|
1242
|
+
a = _Answer(op, data)
|
|
1243
|
+
term, index, expires_at_ms = a.u64(), a.u64(), a.i64()
|
|
1244
|
+
stolen = []
|
|
1245
|
+
for _ in range(a.u8()):
|
|
1246
|
+
ms, seq, deliveries = a.u64(), a.u64(), a.u32()
|
|
1247
|
+
stolen.append(
|
|
1248
|
+
GroupRecord(id=StreamID(timestamp_ms=ms, sequence=seq), deliveries=deliveries)
|
|
1249
|
+
)
|
|
1250
|
+
refused = _group_refusals(a, op)
|
|
1251
|
+
a.done()
|
|
1252
|
+
return GroupStealResult(
|
|
1253
|
+
records=stolen,
|
|
1254
|
+
term=term,
|
|
1255
|
+
index=index,
|
|
1256
|
+
expires_at_ms=expires_at_ms,
|
|
1257
|
+
consumer=consumer,
|
|
1258
|
+
refused=refused,
|
|
1259
|
+
)
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
def decode_group_dlq_list_answer(data: bytes) -> GroupDlqPage:
|
|
1263
|
+
"""stream.group.dlq_list's answer: dead, cursor?."""
|
|
1264
|
+
op = "stream.group.dlq_list"
|
|
1265
|
+
a = _Answer(op, data)
|
|
1266
|
+
dead = []
|
|
1267
|
+
for _ in range(a.u8()):
|
|
1268
|
+
ms, seq, deliveries, failures, dead_at_ms = a.u64(), a.u64(), a.u32(), a.u32(), a.i64()
|
|
1269
|
+
error = a.bytes16().decode("utf-8", errors="replace")
|
|
1270
|
+
dead.append(
|
|
1271
|
+
GroupDeadLetter(
|
|
1272
|
+
id=StreamID(timestamp_ms=ms, sequence=seq),
|
|
1273
|
+
deliveries=deliveries,
|
|
1274
|
+
failures=failures,
|
|
1275
|
+
dead_at_ms=dead_at_ms,
|
|
1276
|
+
error=error,
|
|
1277
|
+
)
|
|
1278
|
+
)
|
|
1279
|
+
cursor = GroupDlqCursor(dead_ns=a.u64(), ms=a.u64(), seq=a.u64()) if a.present() else None
|
|
1280
|
+
a.done()
|
|
1281
|
+
return GroupDlqPage(dead=dead, cursor=cursor)
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
def decode_group_dlq_answer(op: str, data: bytes) -> GroupDlqResult:
|
|
1285
|
+
"""stream.group.dlq_requeue's and dlq_delete's answer: applied, refused, more."""
|
|
1286
|
+
a = _Answer(op, data)
|
|
1287
|
+
applied = a.u32()
|
|
1288
|
+
refused = _group_refusals(a, op)
|
|
1289
|
+
more = a.flag()
|
|
1290
|
+
a.done()
|
|
1291
|
+
return GroupDlqResult(applied=applied, refused=refused, more=more)
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
def decode_queue_dlq_list_answer(data: bytes) -> DlqPage:
|
|
1295
|
+
"""queue.dlq_list's answer: dead, cursor?."""
|
|
1296
|
+
op = "queue.dlq_list"
|
|
1297
|
+
a = _Answer(op, data)
|
|
1298
|
+
messages = []
|
|
1299
|
+
for _ in range(a.u8()):
|
|
1300
|
+
seq, priority, deliveries, failures = a.u64(), a.u32(), a.u32(), a.u32()
|
|
1301
|
+
enqueued_at_ms, dead_at_ms, size = a.i64(), a.i64(), a.u32()
|
|
1302
|
+
payload = a.bytes16()
|
|
1303
|
+
error = a.bytes16().decode("utf-8", errors="replace")
|
|
1304
|
+
messages.append(
|
|
1305
|
+
DeadLetter(
|
|
1306
|
+
seq=seq,
|
|
1307
|
+
priority=priority,
|
|
1308
|
+
deliveries=deliveries,
|
|
1309
|
+
failures=failures,
|
|
1310
|
+
enqueued_at_ms=enqueued_at_ms,
|
|
1311
|
+
dead_at_ms=dead_at_ms,
|
|
1312
|
+
size=size,
|
|
1313
|
+
payload=payload,
|
|
1314
|
+
error=error,
|
|
1315
|
+
)
|
|
1316
|
+
)
|
|
1317
|
+
cursor = DlqCursor(dead_ns=a.u64(), seq=a.u64()) if a.present() else None
|
|
1318
|
+
a.done()
|
|
1319
|
+
return DlqPage(messages=messages, cursor=cursor)
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
def decode_queue_dlq_answer(op: str, data: bytes) -> DlqResult:
|
|
1323
|
+
"""queue.dlq_requeue's and dlq_delete's answer: applied, refused, more."""
|
|
1324
|
+
a = _Answer(op, data)
|
|
1325
|
+
applied = a.u32()
|
|
1326
|
+
refused = _refusals(a, op)
|
|
1327
|
+
more = a.flag()
|
|
1328
|
+
a.done()
|
|
1329
|
+
return DlqResult(applied=applied, refused=refused, more=more)
|
flo/processing.py
CHANGED
|
@@ -34,6 +34,7 @@ if TYPE_CHECKING:
|
|
|
34
34
|
_PROCESSING_STATUS_NAMES = ["running", "stopped", "cancelled", "failed", "completed"]
|
|
35
35
|
# The most jobs one list page holds.
|
|
36
36
|
_MAX_PROCESSING_LIST = 1024
|
|
37
|
+
_NO_LATE_EDGE = (1 << 64) - 1
|
|
37
38
|
|
|
38
39
|
|
|
39
40
|
class ProcessingOperations:
|
|
@@ -211,6 +212,7 @@ def _parse_processing_status(data: bytes) -> ProcessingStatusResult:
|
|
|
211
212
|
[reason_len:u16][reason]
|
|
212
213
|
[running:u8][records_in:u64][records_out:u64][watermark_ms:i64]
|
|
213
214
|
[tick_avg_us:u64][tick_max_us:u64][uptime_ms:u64]
|
|
215
|
+
[late_edge_ms:u64][late_points:u64]
|
|
214
216
|
[yaml_len:u32][yaml]
|
|
215
217
|
The reason is a failed job's, why a running one is held here, or empty.
|
|
216
218
|
"""
|
|
@@ -246,9 +248,18 @@ def _parse_processing_status(data: bytes) -> ProcessingStatusResult:
|
|
|
246
248
|
running = take(1)[0]
|
|
247
249
|
if running > 1:
|
|
248
250
|
raise IncompleteResponseError(f"processing.status answer has a running of {running}")
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
251
|
+
(
|
|
252
|
+
records_in,
|
|
253
|
+
records_out,
|
|
254
|
+
watermark_ms,
|
|
255
|
+
tick_avg_us,
|
|
256
|
+
tick_max_us,
|
|
257
|
+
uptime_ms,
|
|
258
|
+
late_edge_ms,
|
|
259
|
+
late_points,
|
|
260
|
+
) = struct.unpack("<QQqQQQQQ", take(64))
|
|
261
|
+
# maxInt(u64) for the edge: no TS source here, so no count.
|
|
262
|
+
counted = late_edge_ms != _NO_LATE_EDGE
|
|
252
263
|
(yaml_len,) = struct.unpack("<I", take(4))
|
|
253
264
|
yaml = take(yaml_len)
|
|
254
265
|
if pos != len(data):
|
|
@@ -272,6 +283,8 @@ def _parse_processing_status(data: bytes) -> ProcessingStatusResult:
|
|
|
272
283
|
tick_avg_us=tick_avg_us,
|
|
273
284
|
tick_max_us=tick_max_us,
|
|
274
285
|
uptime_ms=uptime_ms,
|
|
286
|
+
late_edge_ms=late_edge_ms if counted else None,
|
|
287
|
+
late_points=late_points if counted else None,
|
|
275
288
|
),
|
|
276
289
|
yaml=yaml,
|
|
277
290
|
)
|