taskqx 0.7.0.dev0__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.
Files changed (52) hide show
  1. taskqx/__init__.py +118 -0
  2. taskqx/__main__.py +5 -0
  3. taskqx/admin.py +29 -0
  4. taskqx/broker/__init__.py +12 -0
  5. taskqx/broker/_time.py +25 -0
  6. taskqx/broker/redis.py +1665 -0
  7. taskqx/broker/redis_admin.py +395 -0
  8. taskqx/broker/redis_calls.py +387 -0
  9. taskqx/broker/redis_components.py +111 -0
  10. taskqx/broker/redis_maintenance.py +117 -0
  11. taskqx/broker/redis_observability.py +120 -0
  12. taskqx/broker/redis_scripts.py +177 -0
  13. taskqx/broker/redis_state_machine.py +214 -0
  14. taskqx/broker/sqlite.py +1385 -0
  15. taskqx/broker/sqlite_admin.py +469 -0
  16. taskqx/broker/sqlite_components.py +124 -0
  17. taskqx/broker/sqlite_maintenance.py +218 -0
  18. taskqx/broker/sqlite_migrations.py +57 -0
  19. taskqx/broker/sqlite_state_machine.py +363 -0
  20. taskqx/capabilities.py +46 -0
  21. taskqx/cli.py +227 -0
  22. taskqx/config.py +57 -0
  23. taskqx/consistency.py +50 -0
  24. taskqx/errors.py +37 -0
  25. taskqx/health.py +27 -0
  26. taskqx/interactive.py +40 -0
  27. taskqx/middleware.py +39 -0
  28. taskqx/naming.py +35 -0
  29. taskqx/observability.py +158 -0
  30. taskqx/pagination.py +43 -0
  31. taskqx/payloads.py +208 -0
  32. taskqx/protocols.py +180 -0
  33. taskqx/py.typed +1 -0
  34. taskqx/retry.py +139 -0
  35. taskqx/scheduler.py +134 -0
  36. taskqx/serialization.py +78 -0
  37. taskqx/shell.py +303 -0
  38. taskqx/submission/__init__.py +19 -0
  39. taskqx/submission/base.py +62 -0
  40. taskqx/submission/observability.py +71 -0
  41. taskqx/submission/redis.py +180 -0
  42. taskqx/submission/routing.py +93 -0
  43. taskqx/submission/service.py +110 -0
  44. taskqx/submission/sqlite.py +161 -0
  45. taskqx/tui.py +1048 -0
  46. taskqx/types.py +280 -0
  47. taskqx/worker.py +300 -0
  48. taskqx-0.7.0.dev0.dist-info/METADATA +275 -0
  49. taskqx-0.7.0.dev0.dist-info/RECORD +52 -0
  50. taskqx-0.7.0.dev0.dist-info/WHEEL +4 -0
  51. taskqx-0.7.0.dev0.dist-info/entry_points.txt +2 -0
  52. taskqx-0.7.0.dev0.dist-info/licenses/LICENSE +21 -0
taskqx/__init__.py ADDED
@@ -0,0 +1,118 @@
1
+ """Taskqx:独立、可嵌入、异步优先的任务消息框架。"""
2
+
3
+ from .broker import (
4
+ RedisBroker,
5
+ RedisStringDedupSubmissionStore,
6
+ RedisSubmissionStore,
7
+ SQLiteBroker,
8
+ SQLiteSubmissionStore,
9
+ )
10
+ from .capabilities import BackendCapabilities, DedupGuarantee, SubmissionCapabilities
11
+ from .config import QueueConfig
12
+ from .consistency import (
13
+ ConsistencyIssue,
14
+ ConsistencyReport,
15
+ KeyspaceMigrationReport,
16
+ RepairReport,
17
+ )
18
+ from .errors import (
19
+ BrokerClosedError,
20
+ LeaseLostError,
21
+ PayloadDecodingError,
22
+ RejectMessage,
23
+ RetryableError,
24
+ SerializerUnavailableError,
25
+ TaskqxError,
26
+ UnsupportedCapabilityError,
27
+ ValidationError,
28
+ )
29
+ from .health import HealthCheck, HealthReport
30
+ from .observability import (
31
+ BrokerEvent,
32
+ EventSink,
33
+ GaugeMetricsSink,
34
+ MetricsSink,
35
+ TaskqxEvent,
36
+ )
37
+ from .payloads import PayloadSchema
38
+ from .protocols import SubmissionStore, TaskBroker, TaskConsumer, TaskDelivery
39
+ from .retry import ExponentialBackoff, FixedBackoff, ImmediateBackoff, RetryPolicy
40
+ from .scheduler import BackendScheduler
41
+ from .serialization import JsonSerializer, Serializer, SerializerRegistry
42
+ from .types import (
43
+ BatchSubmitItemResult,
44
+ ConsumerOptions,
45
+ DeadLetter,
46
+ ExpiredMessage,
47
+ FinishOutcome,
48
+ MessageState,
49
+ MessageStatus,
50
+ MessageSummary,
51
+ Page,
52
+ QueueStats,
53
+ SubmitDecision,
54
+ SubmitRequest,
55
+ SubmitResult,
56
+ TaskMessage,
57
+ )
58
+ from .worker import TaskWorker
59
+
60
+ __all__ = [
61
+ "BackendCapabilities",
62
+ "BackendScheduler",
63
+ "BatchSubmitItemResult",
64
+ "BrokerClosedError",
65
+ "BrokerEvent",
66
+ "ConsistencyIssue",
67
+ "ConsistencyReport",
68
+ "ConsumerOptions",
69
+ "DeadLetter",
70
+ "DedupGuarantee",
71
+ "EventSink",
72
+ "ExpiredMessage",
73
+ "ExponentialBackoff",
74
+ "FinishOutcome",
75
+ "FixedBackoff",
76
+ "GaugeMetricsSink",
77
+ "HealthCheck",
78
+ "HealthReport",
79
+ "ImmediateBackoff",
80
+ "JsonSerializer",
81
+ "KeyspaceMigrationReport",
82
+ "LeaseLostError",
83
+ "MessageState",
84
+ "MessageStatus",
85
+ "MessageSummary",
86
+ "MetricsSink",
87
+ "Page",
88
+ "PayloadDecodingError",
89
+ "PayloadSchema",
90
+ "QueueConfig",
91
+ "QueueStats",
92
+ "RedisBroker",
93
+ "RedisStringDedupSubmissionStore",
94
+ "RedisSubmissionStore",
95
+ "RejectMessage",
96
+ "RepairReport",
97
+ "RetryPolicy",
98
+ "RetryableError",
99
+ "SQLiteBroker",
100
+ "SQLiteSubmissionStore",
101
+ "Serializer",
102
+ "SerializerRegistry",
103
+ "SerializerUnavailableError",
104
+ "SubmissionCapabilities",
105
+ "SubmissionStore",
106
+ "SubmitDecision",
107
+ "SubmitRequest",
108
+ "SubmitResult",
109
+ "TaskBroker",
110
+ "TaskConsumer",
111
+ "TaskDelivery",
112
+ "TaskMessage",
113
+ "TaskWorker",
114
+ "TaskqxError",
115
+ "TaskqxEvent",
116
+ "UnsupportedCapabilityError",
117
+ "ValidationError",
118
+ ]
taskqx/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ """`python -m taskqx` 命令入口。"""
2
+
3
+ from .cli import main
4
+
5
+ raise SystemExit(main())
taskqx/admin.py ADDED
@@ -0,0 +1,29 @@
1
+ """后端共用的管理 API 规则。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .errors import ValidationError
6
+
7
+
8
+ def resolve_replay_dedup_mode(
9
+ *, dedup_mode: str | None, reuse_dedup: bool | None, has_replacement: bool
10
+ ) -> str:
11
+ """解析互斥的 keep/remove/replace 策略,并兼容旧 ``reuse_dedup``。"""
12
+
13
+ if dedup_mode is None:
14
+ return (
15
+ "keep"
16
+ if reuse_dedup is None or reuse_dedup
17
+ else "replace"
18
+ if has_replacement
19
+ else "remove"
20
+ )
21
+ if dedup_mode not in {"keep", "remove", "replace"}:
22
+ raise ValidationError("dedup_mode 必须是 keep、remove 或 replace")
23
+ if reuse_dedup is not None and reuse_dedup != (dedup_mode == "keep"):
24
+ raise ValidationError("dedup_mode 与 reuse_dedup 不能表达冲突的策略")
25
+ if dedup_mode in {"keep", "remove"} and has_replacement:
26
+ raise ValidationError(f"dedup_mode={dedup_mode!r} 时不能指定新的 dedup 参数")
27
+ if dedup_mode == "replace" and not has_replacement:
28
+ raise ValidationError("dedup_mode='replace' 必须提供新的 dedup 参数")
29
+ return dedup_mode
@@ -0,0 +1,12 @@
1
+ """内置 broker 实现。"""
2
+
3
+ from .redis import RedisBroker, RedisStringDedupSubmissionStore, RedisSubmissionStore
4
+ from .sqlite import SQLiteBroker, SQLiteSubmissionStore
5
+
6
+ __all__ = [
7
+ "RedisBroker",
8
+ "RedisStringDedupSubmissionStore",
9
+ "RedisSubmissionStore",
10
+ "SQLiteBroker",
11
+ "SQLiteSubmissionStore",
12
+ ]
taskqx/broker/_time.py ADDED
@@ -0,0 +1,25 @@
1
+ """Backends 共享的 UTC 时间与 ID 辅助函数。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import uuid
6
+ from datetime import datetime, timezone
7
+
8
+ from ..errors import ValidationError
9
+
10
+
11
+ def timestamp(value: datetime) -> float:
12
+ """将带时区的时间转换为 UTC epoch 秒。"""
13
+ if value.tzinfo is None:
14
+ raise ValidationError("时间必须带有时区,且建议使用 UTC")
15
+ return value.astimezone(timezone.utc).timestamp()
16
+
17
+
18
+ def datetime_from_timestamp(value: float | None) -> datetime | None:
19
+ """将 epoch 秒恢复为 UTC datetime。"""
20
+ return None if value is None else datetime.fromtimestamp(value, timezone.utc)
21
+
22
+
23
+ def new_id() -> str:
24
+ """生成无外部依赖且适合任务标识的 UUID。"""
25
+ return str(uuid.uuid4())