saq 0.24.0__py3-none-any.whl → 0.24.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.
- saq/__init__.py +1 -1
- saq/queue/postgres.py +8 -3
- saq/worker.py +2 -1
- {saq-0.24.0.dist-info → saq-0.24.4.dist-info}/METADATA +19 -3
- {saq-0.24.0.dist-info → saq-0.24.4.dist-info}/RECORD +9 -9
- {saq-0.24.0.dist-info → saq-0.24.4.dist-info}/LICENSE +0 -0
- {saq-0.24.0.dist-info → saq-0.24.4.dist-info}/WHEEL +0 -0
- {saq-0.24.0.dist-info → saq-0.24.4.dist-info}/entry_points.txt +0 -0
- {saq-0.24.0.dist-info → saq-0.24.4.dist-info}/top_level.txt +0 -0
saq/__init__.py
CHANGED
saq/queue/postgres.py
CHANGED
@@ -75,6 +75,8 @@ class PostgresQueue(Queue):
|
|
75
75
|
job_lock_sweep: Whether or not the jobs are swept if there's no lock. (default True)
|
76
76
|
priorities: The priority range to dequeue. (default (0, 32767))
|
77
77
|
swept_error_message: The error message to use when sweeping jobs. (default "swept")
|
78
|
+
manage_pool_lifecycle: Whether to have SAQ manage the lifecycle of the connection pool. (default None)
|
79
|
+
If None, the pool will be managed if a pool is not provided, otherwise it will not be managed.
|
78
80
|
"""
|
79
81
|
|
80
82
|
@classmethod
|
@@ -104,6 +106,7 @@ class PostgresQueue(Queue):
|
|
104
106
|
job_lock_sweep: bool = True,
|
105
107
|
priorities: tuple[int, int] = (0, 32767),
|
106
108
|
swept_error_message: str | None = None,
|
109
|
+
manage_pool_lifecycle: bool | None = None,
|
107
110
|
) -> None:
|
108
111
|
super().__init__(name=name, dump=dump, load=load, swept_error_message=swept_error_message)
|
109
112
|
|
@@ -123,7 +126,9 @@ class PostgresQueue(Queue):
|
|
123
126
|
if self.pool.kwargs.get("autocommit") is False:
|
124
127
|
raise ValueError("SAQ Connection pool must have autocommit enabled.")
|
125
128
|
self.pool.kwargs["autocommit"] = True
|
126
|
-
self.
|
129
|
+
self._manage_pool_lifecycle = (
|
130
|
+
manage_pool_lifecycle if manage_pool_lifecycle is not None else pool is None
|
131
|
+
)
|
127
132
|
self.min_size = min_size
|
128
133
|
self.max_size = max_size
|
129
134
|
self.saq_lock_keyspace = saq_lock_keyspace
|
@@ -211,7 +216,7 @@ class PostgresQueue(Queue):
|
|
211
216
|
async def connect(self) -> None:
|
212
217
|
if self._connected:
|
213
218
|
return
|
214
|
-
if
|
219
|
+
if self._manage_pool_lifecycle:
|
215
220
|
await self.pool.open()
|
216
221
|
await self.pool.resize(min_size=self.min_size, max_size=self.max_size)
|
217
222
|
await self.init_db()
|
@@ -236,7 +241,7 @@ class PostgresQueue(Queue):
|
|
236
241
|
await conn.execute("SELECT pg_advisory_unlock_all()")
|
237
242
|
await self.pool.putconn(self._dequeue_conn)
|
238
243
|
self._dequeue_conn = None
|
239
|
-
if
|
244
|
+
if self._manage_pool_lifecycle:
|
240
245
|
await self.pool.close()
|
241
246
|
self._has_sweep_lock = False
|
242
247
|
self._connected = False
|
saq/worker.py
CHANGED
@@ -283,7 +283,8 @@ class Worker:
|
|
283
283
|
|
284
284
|
if task and not task.done():
|
285
285
|
task_data["aborted"] = "abort" if job.error is None else job.error
|
286
|
-
|
286
|
+
# abort should be a blocking operation
|
287
|
+
await cancel_tasks([task], 0)
|
287
288
|
|
288
289
|
await self.queue.finish_abort(job)
|
289
290
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: saq
|
3
|
-
Version: 0.24.
|
3
|
+
Version: 0.24.4
|
4
4
|
Summary: Distributed Python job queue with asyncio and redis
|
5
5
|
Home-page: https://github.com/tobymao/saq
|
6
6
|
Author: Toby Mao
|
@@ -120,11 +120,25 @@ environment variables:
|
|
120
120
|
```
|
121
121
|
|
122
122
|
## Example
|
123
|
+
|
123
124
|
```python
|
124
125
|
import asyncio
|
125
126
|
|
126
127
|
from saq import CronJob, Queue
|
127
128
|
|
129
|
+
|
130
|
+
class DBHelper:
|
131
|
+
"""Helper class for demo purposes"""
|
132
|
+
|
133
|
+
async def disconnect(self):
|
134
|
+
print("Disconnecting from the database")
|
135
|
+
|
136
|
+
async def connect(self):
|
137
|
+
print("Connectiong...")
|
138
|
+
|
139
|
+
def __str__(self):
|
140
|
+
return "Your DBHelper at work"
|
141
|
+
|
128
142
|
# all functions take in context dict and kwargs
|
129
143
|
async def test(ctx, *, a):
|
130
144
|
await asyncio.sleep(0.5)
|
@@ -133,10 +147,12 @@ async def test(ctx, *, a):
|
|
133
147
|
return {"x": a}
|
134
148
|
|
135
149
|
async def cron(ctx):
|
136
|
-
|
150
|
+
print("i am a cron job")
|
137
151
|
|
138
152
|
async def startup(ctx):
|
139
|
-
|
153
|
+
helper = DBHelper()
|
154
|
+
await helper.connect()
|
155
|
+
ctx["db"] = helper
|
140
156
|
|
141
157
|
async def shutdown(ctx):
|
142
158
|
await ctx["db"].disconnect()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
saq/__init__.py,sha256=
|
1
|
+
saq/__init__.py,sha256=n3vtr_Be-JuLNl3gVvNbfTnU8doa0pvssMn114QYFTc,218
|
2
2
|
saq/__main__.py,sha256=N4RNqnCcj7eZbM3OyYaC03_6Cot-y-SxW5Hwx6fuzKU,2440
|
3
3
|
saq/errors.py,sha256=XPJw6J3caSAho4ZybuodIbeuGjboVabLuf3NFOEE-4Q,112
|
4
4
|
saq/job.py,sha256=Pion_buhc4N-5mqnqfwfpzVjv-paP3HHqtMAKB6XIcE,11327
|
@@ -6,11 +6,11 @@ saq/multiplexer.py,sha256=S_mjo7kObSBQ_f8epf0pT5Tjxg-LABW3fSH4dPfZxsE,2332
|
|
6
6
|
saq/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
saq/types.py,sha256=GhIq2BIE_Z9hA-qS-NQXh_iPICNI0NZxOzjW0vcMgFU,3196
|
8
8
|
saq/utils.py,sha256=NdOycT-03zxjhKM8A1i0vzKnkv1UQxvy_Zt4GnO0Zd8,1721
|
9
|
-
saq/worker.py,sha256=
|
9
|
+
saq/worker.py,sha256=wd8LTfF7YQRRrOrxqvZcOpEF4KISD9Ws5WDXm3BFfnY,16730
|
10
10
|
saq/queue/__init__.py,sha256=5LgBHGylCVvrLDcjMCcI2dRRgh0BPdz2TKOdc8NMs2E,87
|
11
11
|
saq/queue/base.py,sha256=KaRv9r0fmlRf2CH6Q72MGHXIk9e3vpPEWo4vt5DL1RA,15460
|
12
12
|
saq/queue/http.py,sha256=V9S26gJbUt5AUIR2ETasSQy4Q_K30eGtguBYHpfcLGU,7739
|
13
|
-
saq/queue/postgres.py,sha256=
|
13
|
+
saq/queue/postgres.py,sha256=J6yENeG3rx7IhmCmSDYqz-eyYTvBvWf7-nsVgkuu-Us,34667
|
14
14
|
saq/queue/postgres_migrations.py,sha256=gI6j-0TzlFFSWxji3Dy9aJ-llboJBm92J4tB_YZ7qI8,2080
|
15
15
|
saq/queue/redis.py,sha256=sa_wzUUlfPw-RZ-v_cnDEJWEFyUi3sy_3YTqG4UklOA,17754
|
16
16
|
saq/web/__init__.py,sha256=NG9LfjgJQxNft0_iZuZ3LnX1I58SfxRwKpycjazBoGE,23
|
@@ -20,9 +20,9 @@ saq/web/starlette.py,sha256=i38xuNcnQvWBY3jyHHu9Uo9ILSBzOwmk5Bq06c3CQzM,4432
|
|
20
20
|
saq/web/static/app.js,sha256=i6PaRvBvt96LOINBdEuKkDvVeM-GA8lJiFg4jtQ3viY,7094
|
21
21
|
saq/web/static/pico.min.css.gz,sha256=qCxIv3wWFMQ7MkvGSHQLwxio3121VvvieOkSjw6fv6o,9263
|
22
22
|
saq/web/static/snabbdom.js.gz,sha256=zSO3Z761TB7bYNQFFEtypD0vCuqWesqPJeE5CuV4xRg,7603
|
23
|
-
saq-0.24.
|
24
|
-
saq-0.24.
|
25
|
-
saq-0.24.
|
26
|
-
saq-0.24.
|
27
|
-
saq-0.24.
|
28
|
-
saq-0.24.
|
23
|
+
saq-0.24.4.dist-info/LICENSE,sha256=p208OXrLf_dMcvuRHpcinfsJdihCqKWbqtFXpw4kyW0,1065
|
24
|
+
saq-0.24.4.dist-info/METADATA,sha256=B9Cb8pazxjQCgnVfRoxoaOsVCPrTOdcMJUG0v-cPVfo,7781
|
25
|
+
saq-0.24.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
26
|
+
saq-0.24.4.dist-info/entry_points.txt,sha256=HkKOud1K15_DV7AEltn8G5Ua10VqIgHaZ4BQit4fdOk,42
|
27
|
+
saq-0.24.4.dist-info/top_level.txt,sha256=FMrrc5EiGr4sQkEDtUMHIpomnWHL9i6xT7B6lvEh8xM,4
|
28
|
+
saq-0.24.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|