saq 0.24.3__tar.gz → 0.24.4__tar.gz

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 (34) hide show
  1. {saq-0.24.3/saq.egg-info → saq-0.24.4}/PKG-INFO +19 -3
  2. {saq-0.24.3 → saq-0.24.4}/README.md +18 -2
  3. {saq-0.24.3 → saq-0.24.4}/saq/__init__.py +1 -1
  4. {saq-0.24.3 → saq-0.24.4}/saq/queue/postgres.py +8 -3
  5. {saq-0.24.3 → saq-0.24.4/saq.egg-info}/PKG-INFO +19 -3
  6. {saq-0.24.3 → saq-0.24.4}/LICENSE +0 -0
  7. {saq-0.24.3 → saq-0.24.4}/MANIFEST.in +0 -0
  8. {saq-0.24.3 → saq-0.24.4}/saq/__main__.py +0 -0
  9. {saq-0.24.3 → saq-0.24.4}/saq/errors.py +0 -0
  10. {saq-0.24.3 → saq-0.24.4}/saq/job.py +0 -0
  11. {saq-0.24.3 → saq-0.24.4}/saq/multiplexer.py +0 -0
  12. {saq-0.24.3 → saq-0.24.4}/saq/py.typed +0 -0
  13. {saq-0.24.3 → saq-0.24.4}/saq/queue/__init__.py +0 -0
  14. {saq-0.24.3 → saq-0.24.4}/saq/queue/base.py +0 -0
  15. {saq-0.24.3 → saq-0.24.4}/saq/queue/http.py +0 -0
  16. {saq-0.24.3 → saq-0.24.4}/saq/queue/postgres_migrations.py +0 -0
  17. {saq-0.24.3 → saq-0.24.4}/saq/queue/redis.py +0 -0
  18. {saq-0.24.3 → saq-0.24.4}/saq/types.py +0 -0
  19. {saq-0.24.3 → saq-0.24.4}/saq/utils.py +0 -0
  20. {saq-0.24.3 → saq-0.24.4}/saq/web/__init__.py +0 -0
  21. {saq-0.24.3 → saq-0.24.4}/saq/web/aiohttp.py +0 -0
  22. {saq-0.24.3 → saq-0.24.4}/saq/web/common.py +0 -0
  23. {saq-0.24.3 → saq-0.24.4}/saq/web/starlette.py +0 -0
  24. {saq-0.24.3 → saq-0.24.4}/saq/web/static/app.js +0 -0
  25. {saq-0.24.3 → saq-0.24.4}/saq/web/static/pico.min.css.gz +0 -0
  26. {saq-0.24.3 → saq-0.24.4}/saq/web/static/snabbdom.js.gz +0 -0
  27. {saq-0.24.3 → saq-0.24.4}/saq/worker.py +0 -0
  28. {saq-0.24.3 → saq-0.24.4}/saq.egg-info/SOURCES.txt +0 -0
  29. {saq-0.24.3 → saq-0.24.4}/saq.egg-info/dependency_links.txt +0 -0
  30. {saq-0.24.3 → saq-0.24.4}/saq.egg-info/entry_points.txt +0 -0
  31. {saq-0.24.3 → saq-0.24.4}/saq.egg-info/requires.txt +0 -0
  32. {saq-0.24.3 → saq-0.24.4}/saq.egg-info/top_level.txt +0 -0
  33. {saq-0.24.3 → saq-0.24.4}/setup.cfg +0 -0
  34. {saq-0.24.3 → saq-0.24.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: saq
3
- Version: 0.24.3
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
@@ -99,11 +99,25 @@ environment variables:
99
99
  ```
100
100
 
101
101
  ## Example
102
+
102
103
  ```python
103
104
  import asyncio
104
105
 
105
106
  from saq import CronJob, Queue
106
107
 
108
+
109
+ class DBHelper:
110
+ """Helper class for demo purposes"""
111
+
112
+ async def disconnect(self):
113
+ print("Disconnecting from the database")
114
+
115
+ async def connect(self):
116
+ print("Connectiong...")
117
+
118
+ def __str__(self):
119
+ return "Your DBHelper at work"
120
+
107
121
  # all functions take in context dict and kwargs
108
122
  async def test(ctx, *, a):
109
123
  await asyncio.sleep(0.5)
@@ -112,10 +126,12 @@ async def test(ctx, *, a):
112
126
  return {"x": a}
113
127
 
114
128
  async def cron(ctx):
115
- print("i am a cron job")
129
+ print("i am a cron job")
116
130
 
117
131
  async def startup(ctx):
118
- ctx["db"] = await create_db()
132
+ helper = DBHelper()
133
+ await helper.connect()
134
+ ctx["db"] = helper
119
135
 
120
136
  async def shutdown(ctx):
121
137
  await ctx["db"].disconnect()
@@ -59,11 +59,25 @@ environment variables:
59
59
  ```
60
60
 
61
61
  ## Example
62
+
62
63
  ```python
63
64
  import asyncio
64
65
 
65
66
  from saq import CronJob, Queue
66
67
 
68
+
69
+ class DBHelper:
70
+ """Helper class for demo purposes"""
71
+
72
+ async def disconnect(self):
73
+ print("Disconnecting from the database")
74
+
75
+ async def connect(self):
76
+ print("Connectiong...")
77
+
78
+ def __str__(self):
79
+ return "Your DBHelper at work"
80
+
67
81
  # all functions take in context dict and kwargs
68
82
  async def test(ctx, *, a):
69
83
  await asyncio.sleep(0.5)
@@ -72,10 +86,12 @@ async def test(ctx, *, a):
72
86
  return {"x": a}
73
87
 
74
88
  async def cron(ctx):
75
- print("i am a cron job")
89
+ print("i am a cron job")
76
90
 
77
91
  async def startup(ctx):
78
- ctx["db"] = await create_db()
92
+ helper = DBHelper()
93
+ await helper.connect()
94
+ ctx["db"] = helper
79
95
 
80
96
  async def shutdown(ctx):
81
97
  await ctx["db"].disconnect()
@@ -14,4 +14,4 @@ __all__ = [
14
14
  "Worker",
15
15
  ]
16
16
 
17
- __version__ = "0.24.3"
17
+ __version__ = "0.24.4"
@@ -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._is_pool_provided = pool is not None
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 not self._is_pool_provided:
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 not self._is_pool_provided:
244
+ if self._manage_pool_lifecycle:
240
245
  await self.pool.close()
241
246
  self._has_sweep_lock = False
242
247
  self._connected = False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: saq
3
- Version: 0.24.3
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
@@ -99,11 +99,25 @@ environment variables:
99
99
  ```
100
100
 
101
101
  ## Example
102
+
102
103
  ```python
103
104
  import asyncio
104
105
 
105
106
  from saq import CronJob, Queue
106
107
 
108
+
109
+ class DBHelper:
110
+ """Helper class for demo purposes"""
111
+
112
+ async def disconnect(self):
113
+ print("Disconnecting from the database")
114
+
115
+ async def connect(self):
116
+ print("Connectiong...")
117
+
118
+ def __str__(self):
119
+ return "Your DBHelper at work"
120
+
107
121
  # all functions take in context dict and kwargs
108
122
  async def test(ctx, *, a):
109
123
  await asyncio.sleep(0.5)
@@ -112,10 +126,12 @@ async def test(ctx, *, a):
112
126
  return {"x": a}
113
127
 
114
128
  async def cron(ctx):
115
- print("i am a cron job")
129
+ print("i am a cron job")
116
130
 
117
131
  async def startup(ctx):
118
- ctx["db"] = await create_db()
132
+ helper = DBHelper()
133
+ await helper.connect()
134
+ ctx["db"] = helper
119
135
 
120
136
  async def shutdown(ctx):
121
137
  await ctx["db"].disconnect()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes