python3-commons 0.21.0__py3-none-any.whl → 0.21.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.
- python3_commons/db/__init__.py +18 -4
- {python3_commons-0.21.0.dist-info → python3_commons-0.21.2.dist-info}/METADATA +6 -6
- {python3_commons-0.21.0.dist-info → python3_commons-0.21.2.dist-info}/RECORD +7 -7
- {python3_commons-0.21.0.dist-info → python3_commons-0.21.2.dist-info}/WHEEL +0 -0
- {python3_commons-0.21.0.dist-info → python3_commons-0.21.2.dist-info}/licenses/AUTHORS.rst +0 -0
- {python3_commons-0.21.0.dist-info → python3_commons-0.21.2.dist-info}/licenses/LICENSE +0 -0
- {python3_commons-0.21.0.dist-info → python3_commons-0.21.2.dist-info}/top_level.txt +0 -0
python3_commons/db/__init__.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import contextlib
|
|
2
3
|
import logging
|
|
3
4
|
import time
|
|
@@ -69,14 +70,19 @@ class AsyncSessionManager:
|
|
|
69
70
|
|
|
70
71
|
logger.debug('Building engine for %r (dsn=%s)', name, dsn)
|
|
71
72
|
|
|
73
|
+
# pool_timeout: seconds SQLAlchemy waits for a connection from the pool.
|
|
74
|
+
# Cap it at the manager's acquire timeout so the pool never blocks
|
|
75
|
+
# longer than the deadline we advertise to callers; falls back to the
|
|
76
|
+
# default so the pool never waits forever.
|
|
77
|
+
config_pool_timeout = getattr(db_config, 'pool_timeout', None) or _DEFAULT_POOL_ACQUIRE_TIMEOUT
|
|
78
|
+
pool_timeout = min(config_pool_timeout, self.pool_acquire_timeout)
|
|
79
|
+
|
|
72
80
|
configuration = {
|
|
73
81
|
'url': str_dsn,
|
|
74
82
|
'echo': db_config.echo,
|
|
75
83
|
'pool_size': db_config.pool_size,
|
|
76
84
|
'max_overflow': db_config.max_overflow,
|
|
77
|
-
|
|
78
|
-
# Falls back to default so the pool never blocks forever.
|
|
79
|
-
'pool_timeout': getattr(db_config, 'pool_timeout', _DEFAULT_POOL_ACQUIRE_TIMEOUT),
|
|
85
|
+
'pool_timeout': pool_timeout,
|
|
80
86
|
'pool_recycle': db_config.pool_recycle,
|
|
81
87
|
'pool_pre_ping': db_config.pool_pre_ping,
|
|
82
88
|
}
|
|
@@ -159,6 +165,14 @@ class AsyncSessionManager:
|
|
|
159
165
|
|
|
160
166
|
try:
|
|
161
167
|
async with session_maker() as session:
|
|
168
|
+
# SQLAlchemy establishes the connection lazily on first use.
|
|
169
|
+
# Force the pool checkout + connect to happen *now*, under a
|
|
170
|
+
# hard deadline, so an exhausted pool or an unreachable DB
|
|
171
|
+
# fails fast here instead of hanging inside the request
|
|
172
|
+
# handler for the duration of pool_timeout.
|
|
173
|
+
async with asyncio.timeout(self.pool_acquire_timeout):
|
|
174
|
+
await session.connection()
|
|
175
|
+
|
|
162
176
|
session_acquired = True
|
|
163
177
|
elapsed = time.monotonic() - t0
|
|
164
178
|
logger.debug('Session acquired for %r in %.3fs', name, elapsed)
|
|
@@ -228,7 +242,7 @@ async def is_healthy(
|
|
|
228
242
|
t0 = time.monotonic()
|
|
229
243
|
|
|
230
244
|
try:
|
|
231
|
-
async with engine.begin() as conn:
|
|
245
|
+
async with asyncio.timeout(timeout), engine.begin() as conn:
|
|
232
246
|
result = await conn.execute(text('SELECT 1'))
|
|
233
247
|
healthy = result.scalar() == 1
|
|
234
248
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python3-commons
|
|
3
|
-
Version: 0.21.
|
|
3
|
+
Version: 0.21.2
|
|
4
4
|
Summary: Re-usable Python3 code
|
|
5
5
|
Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
|
|
6
6
|
License-Expression: GPL-3.0
|
|
@@ -12,13 +12,13 @@ Requires-Python: <3.15.0,>=3.14.0
|
|
|
12
12
|
Description-Content-Type: text/x-rst
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
License-File: AUTHORS.rst
|
|
15
|
-
Requires-Dist: msgpack~=1.
|
|
15
|
+
Requires-Dist: msgpack~=1.2.0
|
|
16
16
|
Requires-Dist: msgspec~=0.21.1
|
|
17
17
|
Requires-Dist: pydantic-settings~=2.14.1
|
|
18
18
|
Provides-Extra: all
|
|
19
19
|
Requires-Dist: python3_commons[api-client,audit,authn,authz,cache,database,object-storage,soap-client]; extra == "all"
|
|
20
20
|
Provides-Extra: api-client
|
|
21
|
-
Requires-Dist: aiohttp[speedups]<3.15.0,>=3.14.
|
|
21
|
+
Requires-Dist: aiohttp[speedups]<3.15.0,>=3.14.1; extra == "api-client"
|
|
22
22
|
Requires-Dist: certifi~=2026.5.20; extra == "api-client"
|
|
23
23
|
Requires-Dist: python3_commons[audit,object-storage]; extra == "api-client"
|
|
24
24
|
Provides-Extra: audit
|
|
@@ -26,7 +26,7 @@ Requires-Dist: lxml~=6.1.1; extra == "audit"
|
|
|
26
26
|
Requires-Dist: zeep[async]~=4.3.2; extra == "audit"
|
|
27
27
|
Requires-Dist: python3_commons[object-storage]; extra == "audit"
|
|
28
28
|
Provides-Extra: authn
|
|
29
|
-
Requires-Dist: aiohttp[speedups]<3.15.0,>=3.14.
|
|
29
|
+
Requires-Dist: aiohttp[speedups]<3.15.0,>=3.14.1; extra == "authn"
|
|
30
30
|
Requires-Dist: certifi~=2026.5.20; extra == "authn"
|
|
31
31
|
Requires-Dist: python3_commons[api-client]; extra == "authn"
|
|
32
32
|
Provides-Extra: authz
|
|
@@ -39,9 +39,9 @@ Requires-Dist: asyncpg~=0.31.0; extra == "database"
|
|
|
39
39
|
Requires-Dist: SQLAlchemy[asyncio]~=2.0.50; extra == "database"
|
|
40
40
|
Provides-Extra: object-storage
|
|
41
41
|
Requires-Dist: aiobotocore~=3.7.0; extra == "object-storage"
|
|
42
|
-
Requires-Dist: object-storage-client~=0.0.
|
|
42
|
+
Requires-Dist: object-storage-client~=0.0.35; extra == "object-storage"
|
|
43
43
|
Provides-Extra: soap-client
|
|
44
|
-
Requires-Dist: aiohttp[speedups]<3.15.0,>=3.14.
|
|
44
|
+
Requires-Dist: aiohttp[speedups]<3.15.0,>=3.14.1; extra == "soap-client"
|
|
45
45
|
Requires-Dist: certifi~=2026.5.20; extra == "soap-client"
|
|
46
46
|
Requires-Dist: lxml~=6.1.1; extra == "soap-client"
|
|
47
47
|
Requires-Dist: requests~=2.34.2; extra == "soap-client"
|
|
@@ -12,7 +12,7 @@ python3_commons/helpers.py,sha256=WTPu_jIOGYtxt1GYnH6sBMNDHry99AKv6ZaggGW2l1A,49
|
|
|
12
12
|
python3_commons/object_storage.py,sha256=2l8v1mDB5WWN6jhxH2t5xmHBXaVPRJl0z44wExmlO80,7175
|
|
13
13
|
python3_commons/permissions.py,sha256=gaMKSWg0MgPQTdP1voll4ItXcblXku9BlD0Lq3Xv64U,1724
|
|
14
14
|
python3_commons/soap_client.py,sha256=w2lOyhhtkhwiNnHjvir8DfjGBO51XVg5rlDHyuudU2A,7169
|
|
15
|
-
python3_commons/db/__init__.py,sha256=
|
|
15
|
+
python3_commons/db/__init__.py,sha256=xBXp86sU1drxShfzhSsoK1lS1EMHuT4hMGVS21Pcp0I,9804
|
|
16
16
|
python3_commons/db/helpers.py,sha256=xRpWs4aVkBge6HCLjb6OLSnWc1nlV6rKGyaVhZ_x12w,2001
|
|
17
17
|
python3_commons/db/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
python3_commons/db/models/auth.py,sha256=t6z_0c7l_1eB-CCdnPSV9OzJ_ymgkwD1cLpecNhQgoA,773
|
|
@@ -27,9 +27,9 @@ python3_commons/serializers/common.py,sha256=VkA7C6wODvHk0QBXVX_x2JieDstihx3U__U
|
|
|
27
27
|
python3_commons/serializers/json.py,sha256=UPkC3ps13x2C_NxwVV-K7Ewp4VjkVHSSUkJVw5k7Wiw,712
|
|
28
28
|
python3_commons/serializers/msgpack.py,sha256=zESFBX34GsZ8rDu6Zk5V6CLT6P0mPilU0r04Ka6TblI,1474
|
|
29
29
|
python3_commons/serializers/msgspec.py,sha256=upy5CBmK66-8hYnK5bAM_sZvZY5CAqZmzCw9GIF346I,2988
|
|
30
|
-
python3_commons-0.21.
|
|
31
|
-
python3_commons-0.21.
|
|
32
|
-
python3_commons-0.21.
|
|
33
|
-
python3_commons-0.21.
|
|
34
|
-
python3_commons-0.21.
|
|
35
|
-
python3_commons-0.21.
|
|
30
|
+
python3_commons-0.21.2.dist-info/licenses/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
|
|
31
|
+
python3_commons-0.21.2.dist-info/licenses/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
|
|
32
|
+
python3_commons-0.21.2.dist-info/METADATA,sha256=Ir14F0udApTBpvt3XipchoCC9WuQbnGLeI2y7nKFbQw,2333
|
|
33
|
+
python3_commons-0.21.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
34
|
+
python3_commons-0.21.2.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
|
|
35
|
+
python3_commons-0.21.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|