qena-shared-lib 0.1.5__py3-none-any.whl → 0.1.7__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.
- qena_shared_lib/exception_handlers.py +16 -3
- qena_shared_lib/logstash/_base.py +1 -1
- qena_shared_lib/rabbitmq/_base.py +1 -1
- qena_shared_lib/rabbitmq/_listener.py +1 -2
- qena_shared_lib/rabbitmq/_pool.py +1 -1
- qena_shared_lib/rabbitmq/_rpc_client.py +1 -2
- qena_shared_lib/utils.py +18 -1
- {qena_shared_lib-0.1.5.dist-info → qena_shared_lib-0.1.7.dist-info}/METADATA +1 -1
- {qena_shared_lib-0.1.5.dist-info → qena_shared_lib-0.1.7.dist-info}/RECORD +10 -11
- qena_shared_lib/rabbitmq/_utils.py +0 -18
- {qena_shared_lib-0.1.5.dist-info → qena_shared_lib-0.1.7.dist-info}/WHEEL +0 -0
@@ -1,9 +1,10 @@
|
|
1
|
+
from collections.abc import Iterable
|
1
2
|
from typing import Any
|
2
3
|
|
3
4
|
from fastapi import Request, Response, status
|
4
|
-
from fastapi.encoders import jsonable_encoder
|
5
5
|
from fastapi.exceptions import RequestValidationError
|
6
6
|
from fastapi.responses import JSONResponse
|
7
|
+
from pydantic_core import to_jsonable_python
|
7
8
|
|
8
9
|
from .dependencies.http import get_service
|
9
10
|
from .exceptions import ServiceException, Severity
|
@@ -93,7 +94,19 @@ def handle_service_exception(
|
|
93
94
|
content["correctiveAction"] = exception.corrective_action
|
94
95
|
|
95
96
|
if exception.body is not None:
|
96
|
-
|
97
|
+
extra_body = to_jsonable_python(exception.body)
|
98
|
+
is_updated = False
|
99
|
+
|
100
|
+
try:
|
101
|
+
if isinstance(extra_body, Iterable):
|
102
|
+
content.update(extra_body)
|
103
|
+
|
104
|
+
is_updated = True
|
105
|
+
except:
|
106
|
+
pass
|
107
|
+
|
108
|
+
if not is_updated:
|
109
|
+
content["data"] = extra_body
|
97
110
|
|
98
111
|
return JSONResponse(
|
99
112
|
content=content,
|
@@ -117,7 +130,7 @@ def handle_request_validation_error(
|
|
117
130
|
"severity": Severity.MEDIUM.name,
|
118
131
|
"message": message,
|
119
132
|
"code": 100,
|
120
|
-
"detail":
|
133
|
+
"detail": to_jsonable_python(error.errors()),
|
121
134
|
},
|
122
135
|
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
123
136
|
)
|
@@ -228,7 +228,6 @@ class BaseLogstashSender(AsyncEventLoopMixin):
|
|
228
228
|
self._max_log_retry = max_log_retry
|
229
229
|
self._started = False
|
230
230
|
self._closed = False
|
231
|
-
self._close_future = self.loop.create_future()
|
232
231
|
self._log_queue: Queue[LogstashLogRecord | EndOfLogMarker] = Queue(
|
233
232
|
log_queue_size
|
234
233
|
)
|
@@ -246,6 +245,7 @@ class BaseLogstashSender(AsyncEventLoopMixin):
|
|
246
245
|
|
247
246
|
self._started = True
|
248
247
|
self._closed = False
|
248
|
+
self._close_future = self.loop.create_future()
|
249
249
|
_, _ = await gather(
|
250
250
|
self.loop.run_in_executor(executor=None, func=self._hook_on_start),
|
251
251
|
self._hook_on_start_async(),
|
@@ -381,7 +381,7 @@ class RabbitMqManager(AsyncEventLoopMixin):
|
|
381
381
|
)
|
382
382
|
|
383
383
|
if self._connected:
|
384
|
-
self.loop.create_task(self._channel_pool.
|
384
|
+
self.loop.create_task(self._channel_pool.drain()).add_done_callback(
|
385
385
|
self._channel_pool_drained
|
386
386
|
)
|
387
387
|
|
@@ -21,11 +21,10 @@ from pydantic_core import from_json, to_json
|
|
21
21
|
from ..dependencies.miscellaneous import validate_annotation
|
22
22
|
from ..logging import LoggerProvider
|
23
23
|
from ..logstash import BaseLogstashSender
|
24
|
-
from ..utils import AsyncEventLoopMixin
|
24
|
+
from ..utils import AsyncEventLoopMixin, TypeAdapterCache
|
25
25
|
from ._channel import BaseChannel
|
26
26
|
from ._exceptions import RabbitMQException
|
27
27
|
from ._pool import ChannelPool
|
28
|
-
from ._utils import TypeAdapterCache
|
29
28
|
|
30
29
|
__all__ = [
|
31
30
|
"BackoffRetryDelay",
|
@@ -28,7 +28,7 @@ class ChannelPool(AsyncEventLoopMixin):
|
|
28
28
|
for _ in range(self._initial_pool_size):
|
29
29
|
await self._add_new_channel()
|
30
30
|
|
31
|
-
async def
|
31
|
+
async def drain(self):
|
32
32
|
async with self._pool_lock:
|
33
33
|
for channel_base in self._pool.values():
|
34
34
|
with channel_base as channel:
|
@@ -13,10 +13,9 @@ from prometheus_client import Counter, Summary
|
|
13
13
|
from pydantic_core import from_json, to_json
|
14
14
|
|
15
15
|
from ..logging import LoggerProvider
|
16
|
-
from ..utils import AsyncEventLoopMixin
|
16
|
+
from ..utils import AsyncEventLoopMixin, TypeAdapterCache
|
17
17
|
from ._exceptions import RabbitMQException
|
18
18
|
from ._pool import ChannelPool
|
19
|
-
from ._utils import TypeAdapterCache
|
20
19
|
|
21
20
|
__all__ = ["RpcClient"]
|
22
21
|
|
qena_shared_lib/utils.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
from asyncio import AbstractEventLoop, get_running_loop
|
2
2
|
|
3
|
-
|
3
|
+
from pydantic import TypeAdapter
|
4
|
+
|
5
|
+
__all__ = ["AsyncEventLoopMixin", "TypeAdapterCache"]
|
4
6
|
|
5
7
|
ABSTRACT_EVENT_LOOP_ATTRIBUTE = "__abstract_event_loop__"
|
6
8
|
|
@@ -26,3 +28,18 @@ class AsyncEventLoopMixin:
|
|
26
28
|
setattr(self, ABSTRACT_EVENT_LOOP_ATTRIBUTE, current_running_loop)
|
27
29
|
|
28
30
|
return getattr(self, ABSTRACT_EVENT_LOOP_ATTRIBUTE)
|
31
|
+
|
32
|
+
|
33
|
+
class TypeAdapterCache:
|
34
|
+
_cache = {}
|
35
|
+
|
36
|
+
@classmethod
|
37
|
+
def cache_annotation(cls, annotation: type):
|
38
|
+
if annotation not in cls._cache:
|
39
|
+
cls._cache[annotation] = TypeAdapter(annotation)
|
40
|
+
|
41
|
+
@classmethod
|
42
|
+
def get_type_adapter(cls, annotation: type) -> TypeAdapter:
|
43
|
+
cls.cache_annotation(annotation)
|
44
|
+
|
45
|
+
return cls._cache[annotation]
|
@@ -1,31 +1,30 @@
|
|
1
1
|
qena_shared_lib/__init__.py,sha256=WokKEFaMNow6h2ZY_fyB-tiYnic-Ed6K6kyzKgg3Rlw,371
|
2
2
|
qena_shared_lib/application.py,sha256=2bpoEHW9FXRjNgBUuij2djfTLbhk01zymqp6kwasRq0,5470
|
3
3
|
qena_shared_lib/background.py,sha256=upWeJ747-4S4xsBOR-P2_oNar1YiaxCpnLhEDvnArmQ,3097
|
4
|
-
qena_shared_lib/exception_handlers.py,sha256=
|
4
|
+
qena_shared_lib/exception_handlers.py,sha256=GclZUv8_QuJtbVSkzux8hxNbZNG7DWI2u0oGXgaEMD4,5143
|
5
5
|
qena_shared_lib/exceptions.py,sha256=cNeksC8ZavKgoqKLBik1NR-lCcdLZzITHMXww5deY5Y,6789
|
6
6
|
qena_shared_lib/http.py,sha256=90bmDfs522KxKBj2o0vO-MgmDqa3EZOfaNUFp1DuUdQ,23864
|
7
7
|
qena_shared_lib/logging.py,sha256=JL6bAmkK1BJA84rZNpvDEmrec3dogQRpSug4fj1Omkw,1618
|
8
8
|
qena_shared_lib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
qena_shared_lib/scheduler.py,sha256=qxM3zdKJnAKUWw8i_I2M5o3uL_fEOTaBzYUBL-HvUzg,11874
|
10
10
|
qena_shared_lib/security.py,sha256=n872UE3eQfezo1lkHwz5hcAngO0VekA_qDQ9LsZ8JZ8,6072
|
11
|
-
qena_shared_lib/utils.py,sha256=
|
11
|
+
qena_shared_lib/utils.py,sha256=y60AKFknK-vus4i-nesgL00BWuAXJyd8Qx79Gi7lRq4,1272
|
12
12
|
qena_shared_lib/dependencies/__init__.py,sha256=W12RgJbhqZ9GiSV1nLlHmpwPzvQv8t7f4JEoazM_WYg,350
|
13
13
|
qena_shared_lib/dependencies/http.py,sha256=3KopQjq05qbYROMPZjji2Zz7qQLU6_2u3qKisLrjLks,1469
|
14
14
|
qena_shared_lib/dependencies/miscellaneous.py,sha256=iGwAjatXb_JVSF13n1vdTRAgSKv19VtHo9ZbjjbkIco,753
|
15
15
|
qena_shared_lib/logstash/__init__.py,sha256=KlWFXqwPGwKM3yWnz0lTmeZymkobxFPPNeOgyfdGu4g,315
|
16
|
-
qena_shared_lib/logstash/_base.py,sha256=
|
16
|
+
qena_shared_lib/logstash/_base.py,sha256=sX0FLr9R4mkYL3KJO6ADlZaqjn3KbGOLyVTfK_ZTbSo,15722
|
17
17
|
qena_shared_lib/logstash/_http_sender.py,sha256=Sq3bJOXuOafqloROGblnmyUd0RuU3zF0QLpQDYjiy-g,1765
|
18
18
|
qena_shared_lib/logstash/_tcp_sender.py,sha256=ncvc3wYxOJPkB7c_0W8vboaxMRJ_1UYGdA8LN2NXUpo,2306
|
19
19
|
qena_shared_lib/rabbitmq/__init__.py,sha256=WKAcKpRXXX9kqfHVEkyX6p2yIWzB07TMsBBWbV8nrKA,1209
|
20
|
-
qena_shared_lib/rabbitmq/_base.py,sha256=
|
20
|
+
qena_shared_lib/rabbitmq/_base.py,sha256=IKWwi7B82dhkIPwvY12l4ko1cjdmedklBxYkUQVQVL0,23069
|
21
21
|
qena_shared_lib/rabbitmq/_channel.py,sha256=R0xzZvLkeE4YWsyLhx8bPDramsTFDZIcCgfsDyFmSB4,5429
|
22
22
|
qena_shared_lib/rabbitmq/_exception_handlers.py,sha256=7-WguEUqUSIdbvCIWn10f2CRaWPCM3MDZ6sxSATCCYA,4762
|
23
23
|
qena_shared_lib/rabbitmq/_exceptions.py,sha256=Mg56Uk4eBEwTnWC91_WPS3_8d-yaqNkbb_32IpX_R-c,1208
|
24
|
-
qena_shared_lib/rabbitmq/_listener.py,sha256=
|
25
|
-
qena_shared_lib/rabbitmq/_pool.py,sha256=
|
24
|
+
qena_shared_lib/rabbitmq/_listener.py,sha256=eYrlaptPoc72y7UMRyo_Lnn_OE0HGVlBJIh5UEptnww,44134
|
25
|
+
qena_shared_lib/rabbitmq/_pool.py,sha256=MGubA-nYxxjgsZRF1yK4UBkzUy65t-suh0W1jZDk5q8,1952
|
26
26
|
qena_shared_lib/rabbitmq/_publisher.py,sha256=48JdpvNzFaw3Bw5LhunFxcjm3qNWz3AXKyXtcpzcohQ,2380
|
27
|
-
qena_shared_lib/rabbitmq/_rpc_client.py,sha256=
|
28
|
-
qena_shared_lib/
|
29
|
-
qena_shared_lib-0.1.
|
30
|
-
qena_shared_lib-0.1.
|
31
|
-
qena_shared_lib-0.1.5.dist-info/RECORD,,
|
27
|
+
qena_shared_lib/rabbitmq/_rpc_client.py,sha256=5hA8IWvydRufYdv0zViIsi6_W2tWkHcmZotgCV2yjfc,8705
|
28
|
+
qena_shared_lib-0.1.7.dist-info/METADATA,sha256=f6AHqMQrm79vJ1H0n_O5t14CnKvFec8zq1xJZi54H-Q,8520
|
29
|
+
qena_shared_lib-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
30
|
+
qena_shared_lib-0.1.7.dist-info/RECORD,,
|
@@ -1,18 +0,0 @@
|
|
1
|
-
from pydantic import TypeAdapter
|
2
|
-
|
3
|
-
__all__ = ["TypeAdapterCache"]
|
4
|
-
|
5
|
-
|
6
|
-
class TypeAdapterCache:
|
7
|
-
_cache = {}
|
8
|
-
|
9
|
-
@classmethod
|
10
|
-
def cache_annotation(cls, annotation: type):
|
11
|
-
if annotation not in cls._cache:
|
12
|
-
cls._cache[annotation] = TypeAdapter(annotation)
|
13
|
-
|
14
|
-
@classmethod
|
15
|
-
def get_type_adapter(cls, annotation: type) -> TypeAdapter:
|
16
|
-
cls.cache_annotation(annotation)
|
17
|
-
|
18
|
-
return cls._cache[annotation]
|
File without changes
|