qena-shared-lib 0.1.14__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":
@@ -451,10 +451,12 @@ class RabbitMqManager(AsyncEventLoopMixin):
451
451
  ).add_done_callback(self._listener_and_service_config_and_init_done)
452
452
 
453
453
  def _configure_listeners(self) -> list[Awaitable[Any]]:
454
- try:
455
- assert self._connection is not None
454
+ assert self._connection is not None
455
+
456
+ listeners_configured_coroutines: list[Awaitable[Any]] = []
456
457
 
457
- return [
458
+ try:
459
+ listeners_configured_coroutines.extend(
458
460
  listener.configure(
459
461
  connection=self._connection,
460
462
  channel_pool=self._channel_pool,
@@ -464,28 +466,36 @@ class RabbitMqManager(AsyncEventLoopMixin):
464
466
  global_retry_policy=self._listener_global_retry_policy,
465
467
  )
466
468
  for listener in self._listeners
467
- ]
469
+ )
468
470
  except Exception as e:
469
471
  listener_configuration_error_future = self.loop.create_future()
470
472
 
471
473
  listener_configuration_error_future.set_exception(e)
474
+ listeners_configured_coroutines.append(
475
+ listener_configuration_error_future
476
+ )
472
477
 
473
- return [listener_configuration_error_future]
478
+ return listeners_configured_coroutines
474
479
 
475
480
  def _initialize_services(self) -> list[Future[Any]]:
476
481
  assert self._connection is not None
477
482
 
483
+ service_initialization_futures: list[Future[Any]] = []
484
+
478
485
  try:
479
- return [
486
+ service_initialization_futures.extend(
480
487
  service.initialize(self._connection, self._channel_pool)
481
488
  for service in self._services
482
- ]
489
+ )
483
490
  except Exception as e:
484
491
  service_initialization_error_future = self.loop.create_future()
485
492
 
486
493
  service_initialization_error_future.set_exception(e)
494
+ service_initialization_futures.append(
495
+ service_initialization_error_future
496
+ )
487
497
 
488
- return [service_initialization_error_future]
498
+ return service_initialization_futures
489
499
 
490
500
  def _listener_and_service_config_and_init_done(
491
501
  self, future: Future[list[Any]]
@@ -521,7 +531,7 @@ class RabbitMqManager(AsyncEventLoopMixin):
521
531
  service_count = len(self._services)
522
532
 
523
533
  self._logger.info(
524
- "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.",
525
535
  params.host,
526
536
  params.port,
527
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.14
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=JYdW-gchL82wGCaRR3mjSAXPUUYd8CAxioZqIBhMc6I,22670
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.14.dist-info/METADATA,sha256=GWGe51QzF_Jixj796LMl2DUSqlV6ERObFO4YERFaEzY,11413
30
- qena_shared_lib-0.1.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
31
- qena_shared_lib-0.1.14.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,,