taskqx 0.7.0.dev0__py3-none-any.whl → 0.7.2__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.
- taskqx/__init__.py +2 -1
- taskqx/broker/redis.py +48 -14
- taskqx/broker/redis_admin.py +4 -1
- taskqx/broker/redis_calls.py +115 -28
- taskqx/broker/redis_maintenance.py +174 -15
- taskqx/broker/redis_scripts.py +92 -11
- taskqx/broker/redis_state_machine.py +20 -1
- taskqx/broker/sqlite.py +33 -4
- taskqx/broker/sqlite_admin.py +2 -2
- taskqx/broker/sqlite_maintenance.py +188 -18
- taskqx/broker/sqlite_state_machine.py +59 -17
- taskqx/config.py +86 -0
- taskqx/naming.py +4 -4
- taskqx/protocols.py +3 -0
- taskqx/submission/redis.py +2 -2
- taskqx/tui.py +1 -1
- taskqx/types.py +1 -2
- {taskqx-0.7.0.dev0.dist-info → taskqx-0.7.2.dist-info}/METADATA +8 -6
- {taskqx-0.7.0.dev0.dist-info → taskqx-0.7.2.dist-info}/RECORD +22 -22
- {taskqx-0.7.0.dev0.dist-info → taskqx-0.7.2.dist-info}/WHEEL +1 -1
- {taskqx-0.7.0.dev0.dist-info → taskqx-0.7.2.dist-info}/entry_points.txt +0 -0
- {taskqx-0.7.0.dev0.dist-info → taskqx-0.7.2.dist-info}/licenses/LICENSE +0 -0
taskqx/__init__.py
CHANGED
|
@@ -8,7 +8,7 @@ from .broker import (
|
|
|
8
8
|
SQLiteSubmissionStore,
|
|
9
9
|
)
|
|
10
10
|
from .capabilities import BackendCapabilities, DedupGuarantee, SubmissionCapabilities
|
|
11
|
-
from .config import QueueConfig
|
|
11
|
+
from .config import AutoCleanupConfig, QueueConfig
|
|
12
12
|
from .consistency import (
|
|
13
13
|
ConsistencyIssue,
|
|
14
14
|
ConsistencyReport,
|
|
@@ -58,6 +58,7 @@ from .types import (
|
|
|
58
58
|
from .worker import TaskWorker
|
|
59
59
|
|
|
60
60
|
__all__ = [
|
|
61
|
+
"AutoCleanupConfig",
|
|
61
62
|
"BackendCapabilities",
|
|
62
63
|
"BackendScheduler",
|
|
63
64
|
"BatchSubmitItemResult",
|
taskqx/broker/redis.py
CHANGED
|
@@ -14,7 +14,7 @@ from typing import Any, Literal, overload
|
|
|
14
14
|
from typing_extensions import Self
|
|
15
15
|
|
|
16
16
|
from ..capabilities import BackendCapabilities, SubmissionCapabilities
|
|
17
|
-
from ..config import QueueConfig
|
|
17
|
+
from ..config import AutoCleanupConfig, QueueConfig
|
|
18
18
|
from ..consistency import (
|
|
19
19
|
ConsistencyIssue,
|
|
20
20
|
ConsistencyReport,
|
|
@@ -100,7 +100,7 @@ class RedisBroker:
|
|
|
100
100
|
"""使用 Redis Lua 原子迁移实现的异步 v0.1 backend。
|
|
101
101
|
|
|
102
102
|
默认命名空间为 ``taskqx``。每个 broker 应使用独立 namespace,便于隔离测试
|
|
103
|
-
|
|
103
|
+
或不同业务。当前仅支持 Redis standalone;Sentinel 和 Cluster 将由独立 backend 提供。
|
|
104
104
|
"""
|
|
105
105
|
|
|
106
106
|
capabilities = BackendCapabilities(
|
|
@@ -132,6 +132,7 @@ class RedisBroker:
|
|
|
132
132
|
consistency_pel_page_size: int = 1_000,
|
|
133
133
|
queues: Mapping[str, QueueConfig] | None = None,
|
|
134
134
|
default_ack_tombstone_ttl: timedelta = timedelta(minutes=5),
|
|
135
|
+
auto_cleanup: AutoCleanupConfig | None = None,
|
|
135
136
|
event_sink: EventSink | None = None,
|
|
136
137
|
events: EventSink | None = None,
|
|
137
138
|
allow_legacy_names: bool = False,
|
|
@@ -153,6 +154,8 @@ class RedisBroker:
|
|
|
153
154
|
or default_ack_tombstone_ttl.total_seconds() <= 0
|
|
154
155
|
):
|
|
155
156
|
raise ValidationError("default_ack_tombstone_ttl 必须为正数 timedelta")
|
|
157
|
+
if auto_cleanup is not None and not isinstance(auto_cleanup, AutoCleanupConfig):
|
|
158
|
+
raise ValidationError("auto_cleanup 必须是 AutoCleanupConfig 或 None")
|
|
156
159
|
validate_persistent_name(
|
|
157
160
|
namespace, label="namespace", allow_legacy=allow_legacy_names
|
|
158
161
|
)
|
|
@@ -166,6 +169,7 @@ class RedisBroker:
|
|
|
166
169
|
max_attempts=default_max_attempts, default_dedup_ttl=default_dedup_ttl
|
|
167
170
|
)
|
|
168
171
|
self._default_ack_tombstone_ttl = default_ack_tombstone_ttl
|
|
172
|
+
self._default_auto_cleanup = auto_cleanup or AutoCleanupConfig()
|
|
169
173
|
self._queues = dict(queues or {})
|
|
170
174
|
for queue, config in self._queues.items():
|
|
171
175
|
validate_persistent_name(
|
|
@@ -216,10 +220,10 @@ class RedisBroker:
|
|
|
216
220
|
return cls(Redis.from_url(url, decode_responses=True), **kwargs)
|
|
217
221
|
|
|
218
222
|
def _queue_key(self, queue: str, kind: str) -> str:
|
|
219
|
-
return f"{self._namespace}:queue:{
|
|
223
|
+
return f"{self._namespace}:queue:{queue}:{kind}"
|
|
220
224
|
|
|
221
225
|
def _message_key(self, queue: str, message_id: str) -> str:
|
|
222
|
-
return f"{self._namespace}:queue:{
|
|
226
|
+
return f"{self._namespace}:queue:{queue}:message:{message_id}"
|
|
223
227
|
|
|
224
228
|
def _legacy_message_key(self, message_id: str) -> str:
|
|
225
229
|
return f"{self._namespace}:message:{message_id}"
|
|
@@ -264,7 +268,7 @@ class RedisBroker:
|
|
|
264
268
|
return f"{self._namespace}:meta:schema_version"
|
|
265
269
|
|
|
266
270
|
def _dedup_key(self, scope: str, key: str) -> str:
|
|
267
|
-
"""以固定长度摘要构造 dedup key
|
|
271
|
+
"""以固定长度摘要构造 dedup key,隔离特殊字符与分隔符。"""
|
|
268
272
|
|
|
269
273
|
scope_hash = hashlib.sha256(scope.encode()).hexdigest()
|
|
270
274
|
key_hash = hashlib.sha256(key.encode()).hexdigest()
|
|
@@ -282,6 +286,14 @@ class RedisBroker:
|
|
|
282
286
|
def _ack_tombstone_ttl(self, queue: str) -> timedelta:
|
|
283
287
|
return self._queue_config(queue).ack_tombstone_ttl or self._default_ack_tombstone_ttl
|
|
284
288
|
|
|
289
|
+
def _auto_cleanup(self, queue: str) -> AutoCleanupConfig:
|
|
290
|
+
config = self._queue_config(queue).auto_cleanup
|
|
291
|
+
return self._default_auto_cleanup if config is None else config
|
|
292
|
+
|
|
293
|
+
def _cleanup_ttl_seconds(self, queue: str, status: MessageStatus) -> float:
|
|
294
|
+
ttl = self._auto_cleanup(queue).ttl_for(status)
|
|
295
|
+
return -1.0 if ttl is None else ttl.total_seconds()
|
|
296
|
+
|
|
285
297
|
def _configure_submission_stores(
|
|
286
298
|
self,
|
|
287
299
|
submission_store: Any | None,
|
|
@@ -349,8 +361,9 @@ class RedisBroker:
|
|
|
349
361
|
async def close(self) -> None:
|
|
350
362
|
"""关闭底层异步 Redis client。"""
|
|
351
363
|
if not self._closed:
|
|
352
|
-
await self._redis.aclose()
|
|
353
364
|
self._closed = True
|
|
365
|
+
await self._maintenance.close()
|
|
366
|
+
await self._redis.aclose()
|
|
354
367
|
|
|
355
368
|
def select_namespace(self, namespace: str) -> None:
|
|
356
369
|
"""Switch this broker's observation and operation namespace."""
|
|
@@ -640,6 +653,21 @@ class RedisBroker:
|
|
|
640
653
|
await self._redis.hset(
|
|
641
654
|
self._message_index_key(), prepared.message_id, prepared.queue
|
|
642
655
|
)
|
|
656
|
+
if prepared.status == MessageStatus.EXPIRED.value:
|
|
657
|
+
expired_ttl = self._auto_cleanup(prepared.queue).ttl_for(
|
|
658
|
+
MessageStatus.EXPIRED
|
|
659
|
+
)
|
|
660
|
+
if expired_ttl is not None:
|
|
661
|
+
cleanup_at = _timestamp(prepared.created_at + expired_ttl)
|
|
662
|
+
await self._redis.hset(
|
|
663
|
+
self._message_key(prepared.queue, prepared.message_id),
|
|
664
|
+
"cleanup_at",
|
|
665
|
+
str(cleanup_at),
|
|
666
|
+
)
|
|
667
|
+
await self._redis.zadd(
|
|
668
|
+
self._queue_key(prepared.queue, "cleanup:expired"),
|
|
669
|
+
{prepared.message_id: cleanup_at},
|
|
670
|
+
)
|
|
643
671
|
await self._submission_observer.record(prepared, message, result)
|
|
644
672
|
|
|
645
673
|
def _reconstruct_replay_message(
|
|
@@ -727,8 +755,8 @@ class RedisBroker:
|
|
|
727
755
|
if catalog:
|
|
728
756
|
return catalog
|
|
729
757
|
queues: set[str] = set()
|
|
730
|
-
prefix = f"{self._namespace}:queue:
|
|
731
|
-
suffix = "
|
|
758
|
+
prefix = f"{self._namespace}:queue:"
|
|
759
|
+
suffix = ":stats"
|
|
732
760
|
async for raw_key in self._redis.scan_iter(
|
|
733
761
|
match=f"{self._namespace}:queue:*:stats"
|
|
734
762
|
):
|
|
@@ -841,6 +869,12 @@ class RedisBroker:
|
|
|
841
869
|
"""回收已到期租约,并把 READY/LEASED 的过期消息移入 EQ。"""
|
|
842
870
|
return await self._maintenance.run(queue)
|
|
843
871
|
|
|
872
|
+
async def cleanup(
|
|
873
|
+
self, queue: str | None = None, *, limit: int | None = None
|
|
874
|
+
) -> int:
|
|
875
|
+
"""按配置的保留策略批量清理已到期的终态消息。"""
|
|
876
|
+
return await self._maintenance.cleanup(queue, limit=limit)
|
|
877
|
+
|
|
844
878
|
async def inspect(self, queue: str) -> QueueStats:
|
|
845
879
|
"""读取队列实时计数与累计计数。"""
|
|
846
880
|
await self.maintain(queue)
|
|
@@ -997,7 +1031,7 @@ class RedisBroker:
|
|
|
997
1031
|
while len(items) < limit:
|
|
998
1032
|
scan_cursor, keys = await self._redis.scan(
|
|
999
1033
|
cursor=scan_cursor,
|
|
1000
|
-
match=f"{self._namespace}:queue:{
|
|
1034
|
+
match=f"{self._namespace}:queue:{queue}:message:*",
|
|
1001
1035
|
count=max(10, limit * 2),
|
|
1002
1036
|
)
|
|
1003
1037
|
for key in keys:
|
|
@@ -1047,7 +1081,7 @@ class RedisBroker:
|
|
|
1047
1081
|
while len(items) < limit:
|
|
1048
1082
|
scan_cursor, keys = await self._redis.scan(
|
|
1049
1083
|
cursor=scan_cursor,
|
|
1050
|
-
match=f"{self._namespace}:queue:{
|
|
1084
|
+
match=f"{self._namespace}:queue:{queue}:message:*",
|
|
1051
1085
|
count=max(10, limit * 2),
|
|
1052
1086
|
)
|
|
1053
1087
|
for key in keys:
|
|
@@ -1173,8 +1207,8 @@ class RedisBroker:
|
|
|
1173
1207
|
missing_dynamic_groups: list[str] = []
|
|
1174
1208
|
unavailable: list[str] = []
|
|
1175
1209
|
try:
|
|
1176
|
-
stream_suffix = "
|
|
1177
|
-
stream_prefix = f"{self._namespace}:queue:
|
|
1210
|
+
stream_suffix = ":stream"
|
|
1211
|
+
stream_prefix = f"{self._namespace}:queue:"
|
|
1178
1212
|
queues = set(self._queues)
|
|
1179
1213
|
async for raw_key in self._redis.scan_iter(
|
|
1180
1214
|
match=f"{self._namespace}:queue:*:stream"
|
|
@@ -1227,7 +1261,7 @@ class RedisBroker:
|
|
|
1227
1261
|
legacy_messages = 0
|
|
1228
1262
|
try:
|
|
1229
1263
|
for pattern in (
|
|
1230
|
-
f"{self._namespace}:queue
|
|
1264
|
+
f"{self._namespace}:queue:*:message:*",
|
|
1231
1265
|
f"{self._namespace}:message:*",
|
|
1232
1266
|
):
|
|
1233
1267
|
async for raw_key in self._redis.scan_iter(match=pattern):
|
|
@@ -1345,7 +1379,7 @@ class RedisBroker:
|
|
|
1345
1379
|
)
|
|
1346
1380
|
message_fields: dict[str, Any] = {}
|
|
1347
1381
|
async for raw_key in self._redis.scan_iter(
|
|
1348
|
-
match=f"{self._namespace}:queue:{
|
|
1382
|
+
match=f"{self._namespace}:queue:{queue}:message:*"
|
|
1349
1383
|
):
|
|
1350
1384
|
fields = await self._redis.hgetall(raw_key)
|
|
1351
1385
|
message_id = _as_text(raw_key).rsplit(":", 1)[-1]
|
taskqx/broker/redis_admin.py
CHANGED
|
@@ -173,7 +173,7 @@ class RedisAdmin:
|
|
|
173
173
|
message_ids = {
|
|
174
174
|
_as_text(raw_key).rsplit(":", 1)[-1]
|
|
175
175
|
async for raw_key in self._broker._redis.scan_iter(
|
|
176
|
-
match=f"{self._broker._namespace}:queue:{
|
|
176
|
+
match=f"{self._broker._namespace}:queue:{queue}:message:*"
|
|
177
177
|
)
|
|
178
178
|
}
|
|
179
179
|
dedup_keys: list[str] = []
|
|
@@ -196,6 +196,9 @@ class RedisAdmin:
|
|
|
196
196
|
"eq",
|
|
197
197
|
"stats",
|
|
198
198
|
"retention",
|
|
199
|
+
"cleanup:acked",
|
|
200
|
+
"cleanup:expired",
|
|
201
|
+
"cleanup:dead_lettered",
|
|
199
202
|
)
|
|
200
203
|
]
|
|
201
204
|
keys = [
|
taskqx/broker/redis_calls.py
CHANGED
|
@@ -8,15 +8,18 @@ be asserted without a Redis server.
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
import base64
|
|
11
|
+
from collections.abc import Sequence
|
|
11
12
|
from dataclasses import dataclass
|
|
12
13
|
from typing import Any, Protocol
|
|
13
14
|
|
|
14
15
|
from ..submission.base import PreparedSubmission
|
|
16
|
+
from ..types import MessageStatus
|
|
15
17
|
from ._time import timestamp as _timestamp
|
|
16
18
|
from .redis_scripts import (
|
|
17
19
|
BATCH_SUBMIT,
|
|
18
20
|
CLAIM,
|
|
19
21
|
CLEANUP_ACKED,
|
|
22
|
+
CLEANUP_TERMINAL,
|
|
20
23
|
DUE_DELAYED,
|
|
21
24
|
EXPIRE,
|
|
22
25
|
EXTEND_LEASE,
|
|
@@ -118,6 +121,7 @@ def claim_call(
|
|
|
118
121
|
token: str,
|
|
119
122
|
lease_until: float,
|
|
120
123
|
entry_id: str,
|
|
124
|
+
expired_cleanup_ttl: float = -1.0,
|
|
121
125
|
) -> RedisScriptCall:
|
|
122
126
|
return RedisScriptCall(
|
|
123
127
|
CLAIM,
|
|
@@ -128,6 +132,7 @@ def claim_call(
|
|
|
128
132
|
backend._queue_key(queue, "expiry"),
|
|
129
133
|
backend._queue_key(queue, "stream"),
|
|
130
134
|
backend._queue_key(queue, "ready"),
|
|
135
|
+
backend._queue_key(queue, "cleanup:expired"),
|
|
131
136
|
),
|
|
132
137
|
(
|
|
133
138
|
str(now),
|
|
@@ -138,6 +143,7 @@ def claim_call(
|
|
|
138
143
|
str(lease_until),
|
|
139
144
|
backend._group_name(),
|
|
140
145
|
entry_id,
|
|
146
|
+
str(expired_cleanup_ttl),
|
|
141
147
|
),
|
|
142
148
|
)
|
|
143
149
|
|
|
@@ -156,25 +162,34 @@ def finish_call(
|
|
|
156
162
|
retry_available_at: float | None,
|
|
157
163
|
max_attempts: int | None,
|
|
158
164
|
ack_tombstone_ttl: float,
|
|
165
|
+
acked_cleanup_ttl: float = -1.0,
|
|
166
|
+
expired_cleanup_ttl: float = -1.0,
|
|
167
|
+
dead_lettered_cleanup_ttl: float = -1.0,
|
|
159
168
|
) -> RedisScriptCall:
|
|
160
169
|
return RedisScriptCall(
|
|
161
170
|
FINISH,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
(
|
|
172
|
+
*(
|
|
173
|
+
backend._queue_key(queue, kind)
|
|
174
|
+
if kind != "message"
|
|
175
|
+
else backend._message_key(queue, message_id)
|
|
176
|
+
for kind in (
|
|
177
|
+
"message",
|
|
178
|
+
"leases",
|
|
179
|
+
"expiry",
|
|
180
|
+
"stream",
|
|
181
|
+
"eq",
|
|
182
|
+
"stats",
|
|
183
|
+
"dlq",
|
|
184
|
+
"ready",
|
|
185
|
+
"delayed",
|
|
186
|
+
"retention",
|
|
187
|
+
"cleanup:acked",
|
|
188
|
+
"cleanup:expired",
|
|
189
|
+
"cleanup:dead_lettered",
|
|
190
|
+
)
|
|
191
|
+
),
|
|
192
|
+
backend._message_index_key(),
|
|
178
193
|
),
|
|
179
194
|
(
|
|
180
195
|
action,
|
|
@@ -188,6 +203,9 @@ def finish_call(
|
|
|
188
203
|
str(retry_available_at) if retry_available_at is not None else "0",
|
|
189
204
|
str(max_attempts or 0),
|
|
190
205
|
str(ack_tombstone_ttl),
|
|
206
|
+
str(acked_cleanup_ttl),
|
|
207
|
+
str(expired_cleanup_ttl),
|
|
208
|
+
str(dead_lettered_cleanup_ttl),
|
|
191
209
|
),
|
|
192
210
|
)
|
|
193
211
|
|
|
@@ -200,6 +218,7 @@ def extend_lease_call(
|
|
|
200
218
|
delivery_id: str,
|
|
201
219
|
token: str,
|
|
202
220
|
lease_until: float,
|
|
221
|
+
expired_cleanup_ttl: float = -1.0,
|
|
203
222
|
) -> RedisScriptCall:
|
|
204
223
|
return RedisScriptCall(
|
|
205
224
|
EXTEND_LEASE,
|
|
@@ -209,8 +228,16 @@ def extend_lease_call(
|
|
|
209
228
|
backend._queue_key(queue, "stream"),
|
|
210
229
|
backend._queue_key(queue, "expiry"),
|
|
211
230
|
backend._queue_key(queue, "eq"),
|
|
231
|
+
backend._queue_key(queue, "cleanup:expired"),
|
|
232
|
+
),
|
|
233
|
+
(
|
|
234
|
+
delivery_id,
|
|
235
|
+
token,
|
|
236
|
+
str(lease_until),
|
|
237
|
+
message_id,
|
|
238
|
+
backend._group_name(),
|
|
239
|
+
str(expired_cleanup_ttl),
|
|
212
240
|
),
|
|
213
|
-
(delivery_id, token, str(lease_until), message_id, backend._group_name()),
|
|
214
241
|
)
|
|
215
242
|
|
|
216
243
|
|
|
@@ -229,7 +256,12 @@ def pel_recover_call(
|
|
|
229
256
|
|
|
230
257
|
|
|
231
258
|
def due_delayed_call(
|
|
232
|
-
backend: RedisKeyspace,
|
|
259
|
+
backend: RedisKeyspace,
|
|
260
|
+
*,
|
|
261
|
+
queue: str,
|
|
262
|
+
message_id: str,
|
|
263
|
+
now: float,
|
|
264
|
+
expired_cleanup_ttl: float = -1.0,
|
|
233
265
|
) -> RedisScriptCall:
|
|
234
266
|
return RedisScriptCall(
|
|
235
267
|
DUE_DELAYED,
|
|
@@ -237,14 +269,27 @@ def due_delayed_call(
|
|
|
237
269
|
backend._queue_key(queue, kind)
|
|
238
270
|
if kind != "message"
|
|
239
271
|
else backend._message_key(queue, message_id)
|
|
240
|
-
for kind in (
|
|
272
|
+
for kind in (
|
|
273
|
+
"message",
|
|
274
|
+
"delayed",
|
|
275
|
+
"ready",
|
|
276
|
+
"stream",
|
|
277
|
+
"eq",
|
|
278
|
+
"expiry",
|
|
279
|
+
"cleanup:expired",
|
|
280
|
+
)
|
|
241
281
|
),
|
|
242
|
-
(str(now), message_id),
|
|
282
|
+
(str(now), message_id, str(expired_cleanup_ttl)),
|
|
243
283
|
)
|
|
244
284
|
|
|
245
285
|
|
|
246
286
|
def expire_call(
|
|
247
|
-
backend: RedisKeyspace,
|
|
287
|
+
backend: RedisKeyspace,
|
|
288
|
+
*,
|
|
289
|
+
queue: str,
|
|
290
|
+
message_id: str,
|
|
291
|
+
now: float,
|
|
292
|
+
expired_cleanup_ttl: float = -1.0,
|
|
248
293
|
) -> RedisScriptCall:
|
|
249
294
|
return RedisScriptCall(
|
|
250
295
|
EXPIRE,
|
|
@@ -260,14 +305,21 @@ def expire_call(
|
|
|
260
305
|
"eq",
|
|
261
306
|
"ready",
|
|
262
307
|
"delayed",
|
|
308
|
+
"cleanup:expired",
|
|
263
309
|
)
|
|
264
310
|
),
|
|
265
|
-
(str(now), backend._group_name(), message_id),
|
|
311
|
+
(str(now), backend._group_name(), message_id, str(expired_cleanup_ttl)),
|
|
266
312
|
)
|
|
267
313
|
|
|
268
314
|
|
|
269
315
|
def reclaim_lease_call(
|
|
270
|
-
backend: RedisKeyspace,
|
|
316
|
+
backend: RedisKeyspace,
|
|
317
|
+
*,
|
|
318
|
+
queue: str,
|
|
319
|
+
message_id: str,
|
|
320
|
+
now: float,
|
|
321
|
+
expired_cleanup_ttl: float = -1.0,
|
|
322
|
+
dead_lettered_cleanup_ttl: float = -1.0,
|
|
271
323
|
) -> RedisScriptCall:
|
|
272
324
|
return RedisScriptCall(
|
|
273
325
|
RECLAIM_LEASE,
|
|
@@ -284,9 +336,17 @@ def reclaim_lease_call(
|
|
|
284
336
|
"stats",
|
|
285
337
|
"eq",
|
|
286
338
|
"ready",
|
|
339
|
+
"cleanup:expired",
|
|
340
|
+
"cleanup:dead_lettered",
|
|
287
341
|
)
|
|
288
342
|
),
|
|
289
|
-
(
|
|
343
|
+
(
|
|
344
|
+
str(now),
|
|
345
|
+
backend._group_name(),
|
|
346
|
+
message_id,
|
|
347
|
+
str(expired_cleanup_ttl),
|
|
348
|
+
str(dead_lettered_cleanup_ttl),
|
|
349
|
+
),
|
|
290
350
|
)
|
|
291
351
|
|
|
292
352
|
|
|
@@ -305,6 +365,33 @@ def cleanup_acked_call(
|
|
|
305
365
|
)
|
|
306
366
|
|
|
307
367
|
|
|
368
|
+
def cleanup_terminal_call(
|
|
369
|
+
backend: RedisKeyspace,
|
|
370
|
+
*,
|
|
371
|
+
queue: str,
|
|
372
|
+
status: MessageStatus,
|
|
373
|
+
message_ids: Sequence[str],
|
|
374
|
+
now: float,
|
|
375
|
+
) -> RedisScriptCall:
|
|
376
|
+
"""Build batched permanent cleanup for due terminal messages of one status."""
|
|
377
|
+
|
|
378
|
+
audit_kind = {
|
|
379
|
+
MessageStatus.DEAD_LETTERED: "dlq",
|
|
380
|
+
MessageStatus.EXPIRED: "eq",
|
|
381
|
+
}.get(status)
|
|
382
|
+
return RedisScriptCall(
|
|
383
|
+
CLEANUP_TERMINAL,
|
|
384
|
+
(
|
|
385
|
+
backend._queue_key(queue, f"cleanup:{status.value}"),
|
|
386
|
+
backend._queue_key(queue, "retention"),
|
|
387
|
+
backend._queue_key(queue, audit_kind) if audit_kind is not None else "",
|
|
388
|
+
backend._message_index_key(),
|
|
389
|
+
*(backend._message_key(queue, message_id) for message_id in message_ids),
|
|
390
|
+
),
|
|
391
|
+
(str(now), status.value, *message_ids),
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
|
|
308
395
|
def replay_dead_letter_call(
|
|
309
396
|
backend: RedisKeyspace,
|
|
310
397
|
*,
|
|
@@ -332,8 +419,8 @@ def replay_dead_letter_call(
|
|
|
332
419
|
new_dedup_key,
|
|
333
420
|
backend._message_key(target_queue, message_id),
|
|
334
421
|
backend._message_index_key(),
|
|
335
|
-
|
|
336
|
-
,
|
|
422
|
+
backend._queue_key(source_queue, "cleanup:dead_lettered"),
|
|
423
|
+
),
|
|
337
424
|
(
|
|
338
425
|
message_id,
|
|
339
426
|
envelope,
|
|
@@ -373,8 +460,8 @@ def replay_expired_call(
|
|
|
373
460
|
new_dedup_key,
|
|
374
461
|
backend._message_key(target_queue, message_id),
|
|
375
462
|
backend._message_index_key(),
|
|
376
|
-
|
|
377
|
-
,
|
|
463
|
+
backend._queue_key(source_queue, "cleanup:expired"),
|
|
464
|
+
),
|
|
378
465
|
(
|
|
379
466
|
message_id,
|
|
380
467
|
envelope,
|