python-cq 0.1.1__tar.gz → 0.1.3__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.
- {python_cq-0.1.1 → python_cq-0.1.3}/PKG-INFO +1 -1
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/__init__.py +2 -0
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/_core/bus.py +2 -1
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/_core/middleware.py +8 -7
- python_cq-0.1.3/cq/middlewares/retry.py +34 -0
- python_cq-0.1.3/cq/py.typed +0 -0
- {python_cq-0.1.1 → python_cq-0.1.3}/pyproject.toml +1 -1
- {python_cq-0.1.1 → python_cq-0.1.3}/README.md +0 -0
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/_core/__init__.py +0 -0
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/_core/command.py +0 -0
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/_core/dto.py +0 -0
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/_core/event.py +0 -0
- {python_cq-0.1.1 → python_cq-0.1.3}/cq/_core/query.py +0 -0
- /python_cq-0.1.1/cq/py.typed → /python_cq-0.1.3/cq/middlewares/__init__.py +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from ._core.bus import Bus
|
|
1
2
|
from ._core.command import Command, CommandBus, command_handler, find_command_bus
|
|
2
3
|
from ._core.dto import DTO
|
|
3
4
|
from ._core.event import Event, EventBus, event_handler, find_event_bus
|
|
@@ -5,6 +6,7 @@ from ._core.middleware import Middleware, MiddlewareResult
|
|
|
5
6
|
from ._core.query import Query, QueryBus, find_query_bus, query_handler
|
|
6
7
|
|
|
7
8
|
__all__ = (
|
|
9
|
+
"Bus",
|
|
8
10
|
"Command",
|
|
9
11
|
"CommandBus",
|
|
10
12
|
"DTO",
|
|
@@ -19,7 +19,7 @@ class MiddlewareGroup[**P, T]:
|
|
|
19
19
|
return iter(self.__middlewares)
|
|
20
20
|
|
|
21
21
|
def add(self, *middlewares: Middleware[P, T]) -> Self:
|
|
22
|
-
self.__middlewares.extend(middlewares)
|
|
22
|
+
self.__middlewares.extend(reversed(middlewares))
|
|
23
23
|
return self
|
|
24
24
|
|
|
25
25
|
async def invoke(
|
|
@@ -44,12 +44,13 @@ class MiddlewareGroup[**P, T]:
|
|
|
44
44
|
try:
|
|
45
45
|
await anext(generator)
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
while True:
|
|
48
|
+
try:
|
|
49
|
+
value = await handler(*args, **kwargs)
|
|
50
|
+
except BaseException as exc:
|
|
51
|
+
await generator.athrow(exc)
|
|
52
|
+
else:
|
|
53
|
+
await generator.asend(value)
|
|
53
54
|
|
|
54
55
|
except StopAsyncIteration:
|
|
55
56
|
...
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from cq import MiddlewareResult
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class RetryMiddleware:
|
|
8
|
+
__slots__ = ("__delay", "__exceptions", "__retry")
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
retry: int,
|
|
13
|
+
delay: float = 0,
|
|
14
|
+
exceptions: tuple[type[BaseException], ...] = (Exception,),
|
|
15
|
+
) -> None:
|
|
16
|
+
self.__delay = delay
|
|
17
|
+
self.__exceptions = exceptions
|
|
18
|
+
self.__retry = retry
|
|
19
|
+
|
|
20
|
+
async def __call__(self, *args: Any, **kwargs: Any) -> MiddlewareResult[Any]:
|
|
21
|
+
retry = self.__retry
|
|
22
|
+
|
|
23
|
+
for attempt in range(1, retry + 1):
|
|
24
|
+
try:
|
|
25
|
+
yield
|
|
26
|
+
|
|
27
|
+
except self.__exceptions as exc:
|
|
28
|
+
if attempt == retry:
|
|
29
|
+
raise exc
|
|
30
|
+
|
|
31
|
+
else:
|
|
32
|
+
break
|
|
33
|
+
|
|
34
|
+
await asyncio.sleep(self.__delay)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|