muffin 0.93.4__py3-none-any.whl → 0.94.2__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.
- muffin/app.py +18 -9
- {muffin-0.93.4.dist-info → muffin-0.94.2.dist-info}/METADATA +1 -1
- {muffin-0.93.4.dist-info → muffin-0.94.2.dist-info}/RECORD +7 -7
- {muffin-0.93.4.dist-info → muffin-0.94.2.dist-info}/LICENSE +0 -0
- {muffin-0.93.4.dist-info → muffin-0.94.2.dist-info}/WHEEL +0 -0
- {muffin-0.93.4.dist-info → muffin-0.94.2.dist-info}/entry_points.txt +0 -0
- {muffin-0.93.4.dist-info → muffin-0.94.2.dist-info}/top_level.txt +0 -0
muffin/app.py
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
from __future__ import annotations
|
3
3
|
|
4
4
|
import logging
|
5
|
+
from contextvars import ContextVar
|
5
6
|
from inspect import isawaitable, stack
|
6
7
|
from logging.config import dictConfig
|
7
|
-
from typing import TYPE_CHECKING, Any, Dict, Mapping, Union
|
8
|
+
from typing import TYPE_CHECKING, Any, Dict, Final, Mapping, Union
|
8
9
|
|
9
10
|
from asgi_tools import App as BaseApp
|
10
|
-
from asgi_tools.
|
11
|
+
from asgi_tools._compat import aio_wait
|
11
12
|
from modconfig import Config
|
12
13
|
|
13
14
|
from muffin.constants import CONFIG_ENV_VARIABLE
|
@@ -21,6 +22,11 @@ if TYPE_CHECKING:
|
|
21
22
|
|
22
23
|
from muffin.plugins import BasePlugin
|
23
24
|
|
25
|
+
BACKGROUND_TASK: Final["ContextVar[set[Awaitable] | None]"] = ContextVar(
|
26
|
+
"background_tasks",
|
27
|
+
default=None,
|
28
|
+
)
|
29
|
+
|
24
30
|
|
25
31
|
class Application(BaseApp):
|
26
32
|
"""The Muffin Application."""
|
@@ -103,9 +109,9 @@ class Application(BaseApp):
|
|
103
109
|
):
|
104
110
|
"""Support background tasks."""
|
105
111
|
await self.lifespan(scope, receive, send)
|
106
|
-
|
107
|
-
if
|
108
|
-
await
|
112
|
+
bgtasks = BACKGROUND_TASK.get()
|
113
|
+
if bgtasks is not None:
|
114
|
+
await aio_wait(*bgtasks)
|
109
115
|
BACKGROUND_TASK.set(None)
|
110
116
|
|
111
117
|
def import_submodules(self, *submodules: str):
|
@@ -125,8 +131,8 @@ class Application(BaseApp):
|
|
125
131
|
package_name = parent_frame.f_locals["__name__"]
|
126
132
|
return import_submodules(package_name, *submodules)
|
127
133
|
|
128
|
-
def
|
129
|
-
"""Await the given awaitable after the
|
134
|
+
def run_after_response(self, task: Awaitable):
|
135
|
+
"""Await the given awaitable after the response is completed.
|
130
136
|
|
131
137
|
.. code-block:: python
|
132
138
|
|
@@ -143,7 +149,7 @@ class Application(BaseApp):
|
|
143
149
|
async def send(request):
|
144
150
|
|
145
151
|
# Schedule any awaitable for later execution
|
146
|
-
app.
|
152
|
+
app.run_after_response(send_email('user@email.com', 'Hello from Muffin!'))
|
147
153
|
|
148
154
|
# Return response to a client immediately
|
149
155
|
# The task will be executed after the response is sent
|
@@ -153,4 +159,7 @@ class Application(BaseApp):
|
|
153
159
|
if not isawaitable(task):
|
154
160
|
raise TypeError("Task must be awaitable") # noqa: TRY003
|
155
161
|
|
156
|
-
BACKGROUND_TASK.set(
|
162
|
+
scheduled = BACKGROUND_TASK.get() or set()
|
163
|
+
scheduled.add(task)
|
164
|
+
|
165
|
+
BACKGROUND_TASK.set(scheduled)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
muffin/__init__.py,sha256=F8Qp4ETX5FqI1832dj2moRAQ5hEb0TO9u4aRjSKXNjI,982
|
2
|
-
muffin/app.py,sha256
|
2
|
+
muffin/app.py,sha256=tfmm9Dc-ZbUM9UwFUAYDIGPMcNJJU3hz5Wt8uwIylYM,5033
|
3
3
|
muffin/constants.py,sha256=Q9Nm3Q4P3llL_irsvNQAkkD3CqlD4zKkGAM4nabzwrg,38
|
4
4
|
muffin/errors.py,sha256=I-vKbMMBiMU07zPdKvoJKqA7s4xYAUA-4oZXrRMRzcM,701
|
5
5
|
muffin/handler.py,sha256=c0b4pwsIF8jmqYwsWn3iuXR5BMwq2e6ASatGcPu9-N4,3667
|
@@ -9,9 +9,9 @@ muffin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
muffin/pytest.py,sha256=vnSEsQP8dJCFeS8nZklzAh7Stc3H-ng3jm6KlnAOMN0,2169
|
10
10
|
muffin/types.py,sha256=wsUj5oAfqSZMoEf-wyFJLBlWa8Mc-eJGqKLr02HxuXE,153
|
11
11
|
muffin/utils.py,sha256=4tdGNAmdEy6LPaf-5rLYx2YMZ5EOe6tXSqAC1GtG_TY,2422
|
12
|
-
muffin-0.
|
13
|
-
muffin-0.
|
14
|
-
muffin-0.
|
15
|
-
muffin-0.
|
16
|
-
muffin-0.
|
17
|
-
muffin-0.
|
12
|
+
muffin-0.94.2.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
|
13
|
+
muffin-0.94.2.dist-info/METADATA,sha256=205DzwT2ZUtnfwD7ki1HeFSkBQ5M3leSOX5cUU_RuSA,12021
|
14
|
+
muffin-0.94.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
15
|
+
muffin-0.94.2.dist-info/entry_points.txt,sha256=Q3DAZGQk-y5n7HmzJ4FrkNizqTRE2OVXsniPQXzS0Bg,87
|
16
|
+
muffin-0.94.2.dist-info/top_level.txt,sha256=b_xNEFyizTmSqZWCTHwcvbycGyADewdsnaLXo2Pq1Ck,7
|
17
|
+
muffin-0.94.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|