engin 0.1.0rc3__py3-none-any.whl → 0.2.0a1__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.
- engin/_dependency.py +3 -0
- engin/_supervisor.py +18 -5
- {engin-0.1.0rc3.dist-info → engin-0.2.0a1.dist-info}/METADATA +2 -2
- {engin-0.1.0rc3.dist-info → engin-0.2.0a1.dist-info}/RECORD +7 -7
- {engin-0.1.0rc3.dist-info → engin-0.2.0a1.dist-info}/WHEEL +0 -0
- {engin-0.1.0rc3.dist-info → engin-0.2.0a1.dist-info}/entry_points.txt +0 -0
- {engin-0.1.0rc3.dist-info → engin-0.2.0a1.dist-info}/licenses/LICENSE +0 -0
engin/_dependency.py
CHANGED
@@ -171,6 +171,9 @@ class Provide(Dependency[Any, T]):
|
|
171
171
|
override: (optional) allow this provider to override other providers for the
|
172
172
|
same type from the same package.
|
173
173
|
"""
|
174
|
+
if not callable(factory):
|
175
|
+
msg = "Provided value is not callable, did you mean to use Supply instead?"
|
176
|
+
raise ValueError(msg)
|
174
177
|
super().__init__(func=factory)
|
175
178
|
self._scope = scope
|
176
179
|
self._override = override
|
engin/_supervisor.py
CHANGED
@@ -15,7 +15,7 @@ if typing.TYPE_CHECKING:
|
|
15
15
|
|
16
16
|
LOG = logging.getLogger("engin")
|
17
17
|
|
18
|
-
|
18
|
+
AsyncFunction: TypeAlias = Callable[[], Awaitable[None]]
|
19
19
|
|
20
20
|
|
21
21
|
class OnException(Enum):
|
@@ -41,15 +41,16 @@ class _SupervisorTask:
|
|
41
41
|
"""
|
42
42
|
Attributes:
|
43
43
|
- factory: a coroutine function that can create the task.
|
44
|
-
- on_exception: determines the behaviour when task raises an exception.
|
44
|
+
- on_exception: determines the behaviour when the task raises an exception.
|
45
45
|
- complete: will be set to true if task stops for any reason except cancellation.
|
46
46
|
- last_exception: the last exception raised by the task.
|
47
47
|
"""
|
48
48
|
|
49
|
-
factory:
|
49
|
+
factory: AsyncFunction
|
50
50
|
on_exception: OnException
|
51
51
|
complete: bool = False
|
52
52
|
last_exception: Exception | None = None
|
53
|
+
shutdown_hook: AsyncFunction | None = None
|
53
54
|
|
54
55
|
async def __call__(self) -> None:
|
55
56
|
# loop to allow for restarting erroring tasks
|
@@ -106,9 +107,17 @@ class Supervisor:
|
|
106
107
|
self._task_group: TaskGroup | None = None
|
107
108
|
|
108
109
|
def supervise(
|
109
|
-
self,
|
110
|
+
self,
|
111
|
+
func: AsyncFunction,
|
112
|
+
*,
|
113
|
+
on_exception: OnException = OnException.SHUTDOWN,
|
114
|
+
shutdown_hook: AsyncFunction | None = None,
|
110
115
|
) -> None:
|
111
|
-
self._tasks.append(
|
116
|
+
self._tasks.append(
|
117
|
+
_SupervisorTask(
|
118
|
+
factory=func, on_exception=on_exception, shutdown_hook=shutdown_hook
|
119
|
+
)
|
120
|
+
)
|
112
121
|
|
113
122
|
@property
|
114
123
|
def empty(self) -> bool:
|
@@ -132,6 +141,10 @@ class Supervisor:
|
|
132
141
|
/,
|
133
142
|
) -> None:
|
134
143
|
if self._task_group:
|
144
|
+
for task in self._tasks:
|
145
|
+
if task.shutdown_hook is not None:
|
146
|
+
LOG.debug(f"supervised task shutdown hook: {task.name}")
|
147
|
+
await task.shutdown_hook()
|
135
148
|
if not self._task_group.cancel_scope.cancel_called:
|
136
149
|
self._task_group.cancel_scope.cancel()
|
137
150
|
await self._task_group.__aexit__(exc_type, exc_value, traceback)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: engin
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.0a1
|
4
4
|
Summary: An async-first modular application framework
|
5
5
|
Project-URL: Homepage, https://github.com/invokermain/engin
|
6
6
|
Project-URL: Documentation, https://engin.readthedocs.io/en/latest/
|
@@ -39,7 +39,7 @@ The Engin framework gives you:
|
|
39
39
|
|
40
40
|
- A fully-featured dependency injection system.
|
41
41
|
- A robust application runtime with lifecycle hooks and supervised background tasks.
|
42
|
-
- Zero
|
42
|
+
- Zero boilerplate code reuse across applications.
|
43
43
|
- Integrations for other frameworks such as FastAPI.
|
44
44
|
- Full async support.
|
45
45
|
- CLI commands to aid local development.
|
@@ -1,13 +1,13 @@
|
|
1
1
|
engin/__init__.py,sha256=O0vS570kZFBq7Kwy4FgeJFIhfo4aIg5mv_Z_9vAQRio,577
|
2
2
|
engin/_assembler.py,sha256=0uXgtcO5M3EHg0I-TQK9y7LOzfxkLFmKia-zLyVHaxA,11178
|
3
3
|
engin/_block.py,sha256=IacP4PoJKRhSQCbQSdoyCtmu362a4vj6qoUQKyaJwzI,3062
|
4
|
-
engin/_dependency.py,sha256=
|
4
|
+
engin/_dependency.py,sha256=Ie-z0obe7Ut6TF1O7BjP3Z7i216ufKqSeT_D82krdAc,9615
|
5
5
|
engin/_engin.py,sha256=1bgZmdmRlwHIZ9pz5rysYgvFu5s8e0gzlc9iq-Of97c,9651
|
6
6
|
engin/_graph.py,sha256=y1g7Lm_Zy5GPEgRsggCKV5DDaDzcwUl8v3IZCK8jyGI,1631
|
7
7
|
engin/_introspect.py,sha256=VdREX6Lhhga5SnEP9G7mjHkgJR4mpqk_SMnmL2zTcqY,966
|
8
8
|
engin/_lifecycle.py,sha256=cSWe3euZkmpxmUPFvph2lsTtvuZbxttEfBL-RnOI7lo,5325
|
9
9
|
engin/_option.py,sha256=nZcdrehp1QwgxMUoIpsM0PJuu1q1pbXzhcVsetbsHpc,223
|
10
|
-
engin/_supervisor.py,sha256=
|
10
|
+
engin/_supervisor.py,sha256=WGio-mfPHo2Wdfqo5ZB66WAoAU2ey0urwM0Dl4vRUTA,4824
|
11
11
|
engin/_type_utils.py,sha256=H3Tl-kJr2wY2RhaTXP9GrMqa2RsXMijHbjHKe1AxGmc,2276
|
12
12
|
engin/exceptions.py,sha256=lSMOJI4Yl-VIM0yDzFWbPhC0mQm4f0WvGULr9SldIaY,2353
|
13
13
|
engin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -20,8 +20,8 @@ engin/_cli/_inspect.py,sha256=_uzldpHA51IX4srpUGzL4lZNiepqucsO9M3Zo83XBBM,3159
|
|
20
20
|
engin/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
21
|
engin/extensions/asgi.py,sha256=7vQFaVs1jxq1KbhHGN8k7x2UFab6SPUq2_hXfX6HiXU,3329
|
22
22
|
engin/extensions/fastapi.py,sha256=7N6i-eZUEZRPo7kcvjS7kbRSY5QAPyKJXSeongSQ-OA,6371
|
23
|
-
engin-0.
|
24
|
-
engin-0.
|
25
|
-
engin-0.
|
26
|
-
engin-0.
|
27
|
-
engin-0.
|
23
|
+
engin-0.2.0a1.dist-info/METADATA,sha256=OntxY2pdrpJuvpqb-zvj2SJwpohHmEjbjLmqc7w1zqE,3949
|
24
|
+
engin-0.2.0a1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
25
|
+
engin-0.2.0a1.dist-info/entry_points.txt,sha256=sW247zZUMxm0b5UKYvPuqQQljYDtU-j2zK3cu7gHwM0,41
|
26
|
+
engin-0.2.0a1.dist-info/licenses/LICENSE,sha256=XHh5LPUPKZWTBqBv2xxN2RU7D59nHoiJGb5RIt8f45w,1070
|
27
|
+
engin-0.2.0a1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|