qena-shared-lib 0.1.13__py3-none-any.whl → 0.1.15__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.
@@ -1,6 +1,5 @@
1
1
  from functools import lru_cache
2
2
  from logging import (
3
- INFO,
4
3
  Formatter,
5
4
  Handler,
6
5
  Logger,
@@ -18,11 +17,6 @@ ROOT_LOGGER_NAME = environ.get("LOGGER_NAME") or "qena_shared_lib"
18
17
 
19
18
 
20
19
  class LoggerProvider:
21
- def __init__(self) -> None:
22
- logger = self.get_logger()
23
-
24
- logger.setLevel(INFO)
25
-
26
20
  @lru_cache
27
21
  @staticmethod
28
22
  def default() -> "LoggerProvider":
@@ -10,10 +10,6 @@ from random import uniform
10
10
  from typing import (
11
11
  Any,
12
12
  Awaitable,
13
- Callable,
14
- Concatenate,
15
- Generic,
16
- ParamSpec,
17
13
  TypeVar,
18
14
  cast,
19
15
  )
@@ -55,13 +51,6 @@ __all__ = [
55
51
  ]
56
52
 
57
53
 
58
- E = TypeVar("E", bound=BaseException)
59
- P = ParamSpec("P")
60
- SyncExceptionHandler = Callable[Concatenate[ListenerContext, E, P], None]
61
- AsyncExcpetionHandler = Callable[
62
- Concatenate[ListenerContext, E, P], Awaitable[None]
63
- ]
64
- ExceptionHandler = SyncExceptionHandler[E, P] | AsyncExcpetionHandler[E, P]
65
54
  R = TypeVar("R")
66
55
 
67
56
 
@@ -75,7 +64,7 @@ class AbstractRabbitMQService(ABC):
75
64
  raise NotImplementedError()
76
65
 
77
66
 
78
- class RabbitMqManager(Generic[E, P], AsyncEventLoopMixin):
67
+ class RabbitMqManager(AsyncEventLoopMixin):
79
68
  RABBITMQ_CONNECTION_STATE = PrometheusEnum(
80
69
  name="rabbitmq_connection_state",
81
70
  documentation="Babbitmq connection state",
@@ -462,10 +451,12 @@ class RabbitMqManager(Generic[E, P], AsyncEventLoopMixin):
462
451
  ).add_done_callback(self._listener_and_service_config_and_init_done)
463
452
 
464
453
  def _configure_listeners(self) -> list[Awaitable[Any]]:
465
- try:
466
- assert self._connection is not None
454
+ assert self._connection is not None
467
455
 
468
- return [
456
+ listeners_configured_coroutines: list[Awaitable[Any]] = []
457
+
458
+ try:
459
+ listeners_configured_coroutines.extend(
469
460
  listener.configure(
470
461
  connection=self._connection,
471
462
  channel_pool=self._channel_pool,
@@ -475,28 +466,36 @@ class RabbitMqManager(Generic[E, P], AsyncEventLoopMixin):
475
466
  global_retry_policy=self._listener_global_retry_policy,
476
467
  )
477
468
  for listener in self._listeners
478
- ]
469
+ )
479
470
  except Exception as e:
480
471
  listener_configuration_error_future = self.loop.create_future()
481
472
 
482
473
  listener_configuration_error_future.set_exception(e)
474
+ listeners_configured_coroutines.append(
475
+ listener_configuration_error_future
476
+ )
483
477
 
484
- return [listener_configuration_error_future]
478
+ return listeners_configured_coroutines
485
479
 
486
480
  def _initialize_services(self) -> list[Future[Any]]:
487
481
  assert self._connection is not None
488
482
 
483
+ service_initialization_futures: list[Future[Any]] = []
484
+
489
485
  try:
490
- return [
486
+ service_initialization_futures.extend(
491
487
  service.initialize(self._connection, self._channel_pool)
492
488
  for service in self._services
493
- ]
489
+ )
494
490
  except Exception as e:
495
491
  service_initialization_error_future = self.loop.create_future()
496
492
 
497
493
  service_initialization_error_future.set_exception(e)
494
+ service_initialization_futures.append(
495
+ service_initialization_error_future
496
+ )
498
497
 
499
- return [service_initialization_error_future]
498
+ return service_initialization_futures
500
499
 
501
500
  def _listener_and_service_config_and_init_done(
502
501
  self, future: Future[list[Any]]
@@ -532,7 +531,7 @@ class RabbitMqManager(Generic[E, P], AsyncEventLoopMixin):
532
531
  service_count = len(self._services)
533
532
 
534
533
  self._logger.info(
535
- "connect to rabbitmq, `%s:%s%s` with `%d` %s and `%d` %s.",
534
+ "connected to rabbitmq, `%s:%s%s` with `%d` %s and `%d` %s.",
536
535
  params.host,
537
536
  params.port,
538
537
  params.virtual_host,
qena_shared_lib/utils.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from asyncio import AbstractEventLoop, get_running_loop
2
+ from typing import Generator
2
3
 
3
4
  from pydantic import TypeAdapter
4
5
 
@@ -32,3 +33,12 @@ class TypeAdapterCache:
32
33
  cls.cache_annotation(annotation)
33
34
 
34
35
  return cls._cache[annotation]
36
+
37
+
38
+ class YieldOnce:
39
+ def __await__(self) -> Generator[None, None, None]:
40
+ return (yield)
41
+
42
+
43
+ def yield_now() -> YieldOnce:
44
+ return YieldOnce()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qena-shared-lib
3
- Version: 0.1.13
3
+ Version: 0.1.15
4
4
  Summary: A shared tools for other services
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: cronsim==2.6
@@ -51,6 +51,7 @@ def main() -> FastAPI:
51
51
  .with_description("A shared tools for other services.")
52
52
  .with_version("0.1.0")
53
53
  .with_environment(Environment.PRODUCTION)
54
+ .with_default_exception_handlers()
54
55
  )
55
56
 
56
57
  app = builder.build()
@@ -131,9 +132,7 @@ class UserController(ControllerBase):
131
132
  def main() -> FastAPI:
132
133
  ...
133
134
 
134
- builder.with_controllers([
135
- UserController
136
- ])
135
+ builder.with_controllers(UserController)
137
136
 
138
137
  ...
139
138
  ```
@@ -161,9 +160,7 @@ async def login(
161
160
  def main() -> FastAPI:
162
161
  ...
163
162
 
164
- builder.with_routers([
165
- router
166
- ])
163
+ builder.with_routers(router)
167
164
 
168
165
  ...
169
166
  ```
@@ -270,6 +267,7 @@ def main() -> FastAPI:
270
267
  container=builder.container,
271
268
  )
272
269
 
270
+ rabbitmq.init_default_exception_handlers()
273
271
  rabbitmq.include_listener(UserConsumer)
274
272
  builder.add_singleton(
275
273
  service=RabbitMqManager,
@@ -293,7 +291,7 @@ async def store_user(
293
291
  publisher = rabbitmq.publisher("UserQueue")
294
292
 
295
293
  await publisher.publish(user)
296
- # await publisher.publish_with_arguments(user)
294
+ # await publisher.publish_as_arguments(user)
297
295
  ```
298
296
 
299
297
  ### RPC client
@@ -625,7 +623,7 @@ class UserController(ControllerBase):
625
623
  UserInfo,
626
624
  Authorization(
627
625
  user_type="ADMIN",
628
- persmission=[
626
+ persmissions=[
629
627
  "READ"
630
628
  ],
631
629
  )
@@ -4,16 +4,16 @@ qena_shared_lib/background.py,sha256=A6ohscchVpBzT2igDnAV6WgbJoQtmjqJYLxZBl6HiNE
4
4
  qena_shared_lib/exception_handlers.py,sha256=wEnmWyLZZBnl1zJpkRNr_m_VNdGr85IBWZxhGdlHe-E,7715
5
5
  qena_shared_lib/exceptions.py,sha256=D9Vs2q03VW_Eo7pD_8RYsZGNkVOOQ4Aq9HpUcnxeRlA,11031
6
6
  qena_shared_lib/http.py,sha256=2u5T9aXmUrg5WoRb3uaKUqG_m_mWey_O-KXi_ANVfz4,25047
7
- qena_shared_lib/logging.py,sha256=NyaKgbaBknti9aYxqrhGhIBuAbybCTmYXrRZtI-Mils,1625
7
+ qena_shared_lib/logging.py,sha256=WpbZ6q3-1QWeTK9PQxUyPJU8sfwK5KDYr8Gkji1QiqQ,1516
8
8
  qena_shared_lib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  qena_shared_lib/scheduler.py,sha256=_qQ7ugxZi_KBAzdKv6bwxJ_5z7dSsfNxmjk0Y7SO7wo,13111
10
10
  qena_shared_lib/security.py,sha256=ZWs_XXkLAk6dvToC8pDyEUareb8mScvPbbHN3SPlZio,6128
11
- qena_shared_lib/utils.py,sha256=BGlQjozpR72WuF7wdeim8LjG2j6gSOrmXbcxNPvydN8,850
11
+ qena_shared_lib/utils.py,sha256=yoDbtEAhqa30Fubh6h5w919Vuybq23M8yWG-YOa3Cqc,1032
12
12
  qena_shared_lib/dependencies/__init__.py,sha256=W12RgJbhqZ9GiSV1nLlHmpwPzvQv8t7f4JEoazM_WYg,350
13
13
  qena_shared_lib/dependencies/http.py,sha256=IBsMnRr8Jh8ixf2IcU6n1aYRMazI3fF9GLZxHM2dsXk,1492
14
14
  qena_shared_lib/dependencies/miscellaneous.py,sha256=iGwAjatXb_JVSF13n1vdTRAgSKv19VtHo9ZbjjbkIco,753
15
15
  qena_shared_lib/rabbitmq/__init__.py,sha256=1Rw7OP-A9UacuQWHzKbSOa9zFHa4FsEyFTVgAps01tw,1267
16
- qena_shared_lib/rabbitmq/_base.py,sha256=Bf9gV5MSUQrVgky9FxLr0Htp7lv2mdYiVftacSzLHQk,23043
16
+ qena_shared_lib/rabbitmq/_base.py,sha256=CSqd6ldsgr9mw4al2nQoG5bKPA-C4o4LzAwoEQCXcK0,23075
17
17
  qena_shared_lib/rabbitmq/_channel.py,sha256=yb3pCv6i7D5zXAvusOM3aSw-MWy-wfbEym4mOlKZV9E,5882
18
18
  qena_shared_lib/rabbitmq/_exception_handlers.py,sha256=Gc8IXWLddl0qr7KHXWjyq_Rl52zMlb8iQiLO-2zwvlk,5757
19
19
  qena_shared_lib/rabbitmq/_listener.py,sha256=i3Y8pqUuVl_I5Fxt8o-KFEPIbZSL9_oj8pFhUCwOcgo,48346
@@ -26,6 +26,6 @@ qena_shared_lib/remotelogging/logstash/__init__.py,sha256=-sg2V8gYuAKtnHSXfLorpd
26
26
  qena_shared_lib/remotelogging/logstash/_base.py,sha256=ZNxE9SjZJW3sWKUUn3i52__X0mZuykaZLL3mp-52EOQ,961
27
27
  qena_shared_lib/remotelogging/logstash/_http_sender.py,sha256=kTUdHE1OOSI72tDbIxmwv1-g8shHldfZ0-nBoSu8TyU,1810
28
28
  qena_shared_lib/remotelogging/logstash/_tcp_sender.py,sha256=hIxDW2zEM07rr7BtgmJ5gR9Cs-MXiPD9qtQoVnrmNJ8,2467
29
- qena_shared_lib-0.1.13.dist-info/METADATA,sha256=04KQYaa0W6oMZGRfMrQTHphal21JOMFsKCpxgy2SKMA,11413
30
- qena_shared_lib-0.1.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
31
- qena_shared_lib-0.1.13.dist-info/RECORD,,
29
+ qena_shared_lib-0.1.15.dist-info/METADATA,sha256=0Ui43efIzEMkNzEegB_eIiplixudGXV4j-ARaw8HHZs,11470
30
+ qena_shared_lib-0.1.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
31
+ qena_shared_lib-0.1.15.dist-info/RECORD,,