qena-shared-lib 0.1.5__tar.gz → 0.1.7__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 (43) hide show
  1. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/PKG-INFO +1 -1
  2. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/pyproject.toml +1 -1
  3. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/exception_handlers.py +16 -3
  4. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_base.py +1 -1
  5. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_listener.py +1 -2
  6. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_pool.py +1 -1
  7. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_rpc_client.py +1 -2
  8. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/utils.py +18 -1
  9. qena_shared_lib-0.1.5/src/qena_shared_lib/rabbitmq/_utils.py +0 -18
  10. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/.gitignore +0 -0
  11. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/.pre-commit-config.yaml +0 -0
  12. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/README.md +0 -0
  13. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/requirements.txt +0 -0
  14. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/__init__.py +0 -0
  15. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/application.py +0 -0
  16. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/background.py +0 -0
  17. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/dependencies/__init__.py +0 -0
  18. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/dependencies/http.py +0 -0
  19. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/dependencies/miscellaneous.py +0 -0
  20. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/exceptions.py +0 -0
  21. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/http.py +0 -0
  22. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/logging.py +0 -0
  23. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/logstash/__init__.py +0 -0
  24. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/logstash/_base.py +1 -1
  25. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/logstash/_http_sender.py +0 -0
  26. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/logstash/_tcp_sender.py +0 -0
  27. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/py.typed +0 -0
  28. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/__init__.py +0 -0
  29. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_channel.py +0 -0
  30. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_exception_handlers.py +0 -0
  31. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_exceptions.py +0 -0
  32. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/rabbitmq/_publisher.py +0 -0
  33. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/scheduler.py +0 -0
  34. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/src/qena_shared_lib/security.py +0 -0
  35. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/conftest.py +0 -0
  36. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/test_application.py +0 -0
  37. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/test_background.py +0 -0
  38. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/test_dependencies.py +0 -0
  39. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/test_logstash.py +0 -0
  40. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/test_rabbitmq.py +0 -0
  41. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/test_scheduler.py +0 -0
  42. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/tests/test_security.py +0 -0
  43. {qena_shared_lib-0.1.5 → qena_shared_lib-0.1.7}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qena-shared-lib
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: A shared tools for other services
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: cronsim~=2.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "qena-shared-lib"
3
- version = "0.1.5"
3
+ version = "0.1.7"
4
4
  description = "A shared tools for other services"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -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
- content.update(dict(exception.body))
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": jsonable_encoder(error.errors()),
133
+ "detail": to_jsonable_python(error.errors()),
121
134
  },
122
135
  status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
123
136
  )
@@ -381,7 +381,7 @@ class RabbitMqManager(AsyncEventLoopMixin):
381
381
  )
382
382
 
383
383
  if self._connected:
384
- self.loop.create_task(self._channel_pool.dain()).add_done_callback(
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 dain(self):
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
 
@@ -1,6 +1,8 @@
1
1
  from asyncio import AbstractEventLoop, get_running_loop
2
2
 
3
- __all__ = ["AsyncEventLoopMixin"]
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,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]
@@ -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(),
File without changes