queue-max 0.1.0__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.
@@ -0,0 +1,233 @@
1
+ Metadata-Version: 2.4
2
+ Name: queue-max
3
+ Version: 0.1.0
4
+ Summary: Task queue with SQLite sharding, rate limiting, and circuit breaker
5
+ Author: Alexandre All
6
+ License: MIT
7
+ Project-URL: homepage, https://github.com/all451/queue-max
8
+ Project-URL: repository, https://github.com/all451/queue-max
9
+ Keywords: queue,task-queue,sqlite,background-tasks,worker,sharding
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: System :: Distributed Computing
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: typing-extensions>=4.5.0
26
+ Provides-Extra: webhook
27
+ Requires-Dist: requests>=2.31.0; extra == "webhook"
28
+ Provides-Extra: django
29
+ Requires-Dist: Django>=3.2; extra == "django"
30
+ Provides-Extra: fastapi
31
+ Requires-Dist: fastapi>=0.100.0; extra == "fastapi"
32
+ Provides-Extra: flask
33
+ Requires-Dist: Flask>=2.0; extra == "flask"
34
+ Provides-Extra: all
35
+ Requires-Dist: requests>=2.31.0; extra == "all"
36
+ Requires-Dist: Django>=3.2; extra == "all"
37
+ Requires-Dist: fastapi>=0.100.0; extra == "all"
38
+ Requires-Dist: Flask>=2.0; extra == "all"
39
+ Dynamic: license-file
40
+
41
+ # Queue Max
42
+
43
+ Task queue library with SQLite persistence, sharding, rate limiting, and circuit breaker.
44
+
45
+ No Redis or RabbitMQ required. Zero external dependencies (except typing-extensions).
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ pip install queue-max
51
+ ```
52
+
53
+ With framework integrations:
54
+
55
+ ```bash
56
+ pip install queue-max[django]
57
+ pip install queue-max[fastapi]
58
+ pip install queue-max[flask]
59
+ ```
60
+
61
+ ## Quick Start
62
+
63
+ ```python
64
+ from queue_max import Queue, Worker
65
+
66
+ # Create queue
67
+ queue = Queue()
68
+
69
+ # Enqueue a job
70
+ queue.enqueue({"task": "send_email", "to": "user@example.com"}, priority=2)
71
+
72
+ # Define processor
73
+ def process(payload):
74
+ print(f"Processing: {payload}")
75
+
76
+ # Start worker
77
+ worker = Worker("worker-1", process, queue)
78
+ worker.start()
79
+ ```
80
+
81
+ ## Features
82
+
83
+ **SQLite Persistence** -- Jobs are stored in SQLite with WAL mode. No external services needed.
84
+
85
+ **Physical Sharding** -- Multiple .db files allow concurrent read/write across workers.
86
+
87
+ **Rate Limiting** -- Token bucket algorithm shared across all workers. Configurable per minute.
88
+
89
+ **Circuit Breaker** -- Stops calling failing services after N consecutive errors. Recovers automatically.
90
+
91
+ **Retry with Backoff** -- Exponential backoff with jitter for failed jobs. Configurable max retries.
92
+
93
+ **Heartbeat and Recovery** -- Workers send periodic heartbeats. Orphaned jobs are recovered automatically.
94
+
95
+ **Priority Queues** -- Three levels: low (0), medium (1), high (2).
96
+
97
+ **CLI** -- Built-in command line for stats, workers, and queue management.
98
+
99
+ ## Configuration via Environment Variables
100
+
101
+ | Variable | Default | Description |
102
+ |----------|---------|-------------|
103
+ | NUM_SHARDS | 6 | Number of shard databases |
104
+ | RATE_LIMIT_MAX | 160 | Max requests per minute |
105
+ | QUEUE_MAX_RETRIES | 3 | Default max retry attempts |
106
+ | DB_BUSY_TIMEOUT | 30000 | SQLite busy timeout (ms) |
107
+ | HEARTBEAT_INTERVAL | 5000 | Worker heartbeat interval (ms) |
108
+ | STUCK_TIMEOUT | 30000 | Orphan job timeout (ms) |
109
+ | DATA_DIR | ./data | Directory for shard files |
110
+
111
+ ## API Overview
112
+
113
+ ### Queue
114
+
115
+ ```python
116
+ from queue_max import Queue
117
+
118
+ queue = Queue(shards=6, rate_limit=160, max_retries=3)
119
+
120
+ # Enqueue jobs
121
+ queue.enqueue(payload, pagina_id=None, priority=0, max_retries=None)
122
+ queue.enqueue_batch([{"payload": {...}}, ...])
123
+
124
+ # Process jobs
125
+ job = queue.pop_job(worker_id)
126
+ queue.complete_job(job_id, shard_id)
127
+ queue.fail_job(job_id, shard_id, error, permanent=False)
128
+
129
+ # Management
130
+ queue.retry_failed_jobs()
131
+ queue.cleanup_old_jobs(days=7)
132
+ queue.recover_orphans()
133
+ stats = queue.get_stats()
134
+ ```
135
+
136
+ ### Worker
137
+
138
+ ```python
139
+ from queue_max import Worker, WorkerPool
140
+
141
+ worker = Worker("worker-1", process_function, queue)
142
+ worker.start()
143
+ worker.stop()
144
+
145
+ pool = WorkerPool([worker1, worker2])
146
+ pool.start_all()
147
+ pool.stop_all()
148
+ ```
149
+
150
+ ### Decorator
151
+
152
+ ```python
153
+ from queue_max import task
154
+
155
+ @task(priority=2, max_retries=3)
156
+ def send_email(to: str, subject: str):
157
+ return send(to, subject)
158
+
159
+ send_email.delay("user@example.com", "Hello")
160
+ ```
161
+
162
+ ### CLI
163
+
164
+ ```bash
165
+ queue-max stats
166
+ queue-max worker --function mymodule:myfunction --workers 4
167
+ queue-max enqueue --payload '{"task": "test"}' --priority 2
168
+ queue-max list --status failed --limit 20
169
+ queue-max retry
170
+ queue-max purge --days 7
171
+ ```
172
+
173
+ ## Framework Integrations
174
+
175
+ ### Django
176
+
177
+ ```python
178
+ # settings.py
179
+ INSTALLED_APPS = ["queue_max.contrib.django", ...]
180
+ QUEUE_MAX = {"SHARDS": 4, "RATE_LIMIT": 160}
181
+
182
+ # tasks.py
183
+ from queue_max.contrib.django import task
184
+ @task
185
+ def my_task(user_id): ...
186
+ ```
187
+
188
+ Management commands: `python manage.py queue_worker`, `queue_stats`, `queue_purge`.
189
+
190
+ ### FastAPI
191
+
192
+ ```python
193
+ from fastapi import FastAPI
194
+ from queue_max.contrib.fastapi import QueueMiddleware
195
+
196
+ app = FastAPI()
197
+ app.add_middleware(QueueMiddleware, max_workers=4)
198
+ ```
199
+
200
+ ### Flask
201
+
202
+ ```python
203
+ from flask import Flask
204
+ from queue_max.contrib.flask import QueueExtension
205
+
206
+ app = Flask(__name__)
207
+ queue = QueueExtension(app)
208
+
209
+ @queue.task
210
+ def my_task(): ...
211
+ ```
212
+
213
+ ## Performance
214
+
215
+ | Cenário | Throughput |
216
+ |---------|-----------|
217
+ | Burst (20 workers, 10 shards) | **~3.300 jobs/sec** |
218
+ | Contenção (10 workers, 1 shard) | **~1.660 jobs/sec** |
219
+ | Com 30% de falhas (8 workers) | **Estável** — circuit breaker não trip |
220
+
221
+ - Max queue size: 1M+ jobs per shard
222
+ - [Resultados detalhados dos stress tests](docs/stress-test.md)
223
+
224
+ ## Running Tests
225
+
226
+ ```bash
227
+ pip install -e ".[dev]"
228
+ pytest tests/ -v
229
+ ```
230
+
231
+ ## License
232
+
233
+ MIT
@@ -0,0 +1,30 @@
1
+ queue_max/__init__.py,sha256=pVW2jQZZR9FDcgGCQH9idcHb67T13QlwO3u4mBnzTW0,1679
2
+ queue_max/cli.py,sha256=ozBGmcqg2PT0LJ__0xonkhvQd1CR4bVCkc58_RGyzlE,11214
3
+ queue_max/exceptions.py,sha256=M9HTmNwkPQgBeQOuj8cUfUdppqzFcGfKBRZMJXyDAHE,656
4
+ queue_max/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ queue_max/contrib/__init__.py,sha256=p4u__-xXmLjszOqJh0wTvvFK6rnzUpz65n4xgfnWOd0,189
6
+ queue_max/contrib/django/__init__.py,sha256=jMKt6ZOEkSJzqXKGKIaINk1IhDuRjBi-W0idzf4L3zY,1508
7
+ queue_max/contrib/django/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ queue_max/contrib/django/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ queue_max/contrib/django/management/commands/queue_purge.py,sha256=5JLfMh4qs_tkdmmN2vYZuWVQZdfr7c43T6seQ1wLrCw,634
10
+ queue_max/contrib/django/management/commands/queue_stats.py,sha256=JSBXPqinpwsmWWF68oWG9N0pbUEAPc-O57S3WGqtIJw,1376
11
+ queue_max/contrib/django/management/commands/queue_worker.py,sha256=0Sf1bvoKz9pPGxqkfukc19ws4PyKBaRIWu2LZdBBbxU,1975
12
+ queue_max/contrib/fastapi/__init__.py,sha256=iKA1YcnJsfqypG_vbJn1AoNhkU9FLhjfZQJlmQktTcw,3361
13
+ queue_max/contrib/flask/__init__.py,sha256=_2vudihmqns6U3soeJYw83Rn5xTjJmPlEf72CrWz4f0,2654
14
+ queue_max/core/__init__.py,sha256=EraVVCNdXC0GjJJqUxWM_0O7cvRAOYusjYoOxoqBDaE,424
15
+ queue_max/core/circuit_breaker.py,sha256=Afd-KGgXG9WItXVf2wMKZ8Ejmh7SNDZ37yzeCxqods8,5581
16
+ queue_max/core/database.py,sha256=SPIYkbKNTOdGSCoB4vwfp5ZglJ8TG7MSag2Tvk-eGYU,13690
17
+ queue_max/core/decorator.py,sha256=xevadJn6MOJU3QGQv9WLjwIlAjhIAxVGqTwyJyupl00,11799
18
+ queue_max/core/queue.py,sha256=OCuPzwdywGg5qske2Nk-Ke7Ia0DBuBR8AU7VbBqctb4,14718
19
+ queue_max/core/rate_limiter.py,sha256=atifI2hciW-v6ymytZ1PK9wzG0C6G0MFvRrNeL1MaKs,7503
20
+ queue_max/core/worker.py,sha256=ft06MwSfLKmqpEzZqp3hLy7bMB3CJxASmqZa7bEwXyY,16328
21
+ queue_max/models/__init__.py,sha256=mscNDISJQODwSVSMEehwzcmEzFplIZZRUuRfvxFq-Os,170
22
+ queue_max/models/job.py,sha256=Jv6HvjqThowCRHyXEM-5aGJnx_GBO1A4pRLdOBUFueI,12151
23
+ queue_max/utils/__init__.py,sha256=sTK3MKr466GUciFjaNgvUQuqorDRhpTsTQdl4ORiwYM,421
24
+ queue_max/utils/helpers.py,sha256=KYUPMhZEmv2qAsxO9uiR2Y4zLpsQVNvbd8PBq2og17E,4531
25
+ queue_max-0.1.0.dist-info/licenses/LICENSE,sha256=n-RhQRnO7EIKDJj0Wfg1C_M8zFWTlgLZG3X1JEBVmnY,1083
26
+ queue_max-0.1.0.dist-info/METADATA,sha256=wCJoiTMzyx0GtefEoaRMmRR6sDqX7JfIxjNLvoJCz1I,5913
27
+ queue_max-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
28
+ queue_max-0.1.0.dist-info/entry_points.txt,sha256=fxGeS2pxnBTZQmHptITP9OSQXB5MBmHe8BuaL_CEbJk,49
29
+ queue_max-0.1.0.dist-info/top_level.txt,sha256=C3fzMf7hh4gllaPe6_UvcxHph7xbamwBhHfxADmwgno,10
30
+ queue_max-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ queue-max = queue_max.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Robusta Queue Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ queue_max