Skip to content

Commit 0d4a793

Browse files
committed
🎨 Refactor long-running tasks manager key to use web.AppKey for consistency
1 parent c4aabf4 commit 0d4a793

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

packages/service-library/src/servicelib/aiohttp/long_running_tasks/_constants.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from pydantic import PositiveFloat
44

55
MINUTE: Final[PositiveFloat] = 60
6-
APP_LONG_RUNNING_MANAGER_KEY: Final[str] = (
7-
f"{__name__ }.long_running_tasks.tasks_manager"
8-
)
6+
97
RQT_LONG_RUNNING_TASKS_CONTEXT_KEY: Final[str] = (
108
f"{__name__}.long_running_tasks.context"
119
)
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from typing import Final
2+
13
from aiohttp import web
24

35
from ...long_running_tasks.manager import LongRunningManager
46
from ...long_running_tasks.models import TaskContext
5-
from ._constants import APP_LONG_RUNNING_MANAGER_KEY
67
from ._request import get_task_context
78

89

@@ -13,6 +14,10 @@ def get_task_context(request: web.Request) -> TaskContext:
1314
return get_task_context(request)
1415

1516

17+
APP_LONG_RUNNING_MANAGER_APPKEY: Final = web.AppKey(
18+
"APP_LONG_RUNNING_MANAGER", AiohttpLongRunningManager
19+
)
20+
21+
1622
def get_long_running_manager(app: web.Application) -> AiohttpLongRunningManager:
17-
output: AiohttpLongRunningManager = app[APP_LONG_RUNNING_MANAGER_KEY]
18-
return output
23+
return app[APP_LONG_RUNNING_MANAGER_APPKEY]

packages/service-library/src/servicelib/aiohttp/long_running_tasks/_server.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@
3030
from ..typing_extension import Handler
3131
from . import _routes
3232
from ._constants import (
33-
APP_LONG_RUNNING_MANAGER_KEY,
3433
RQT_LONG_RUNNING_TASKS_CONTEXT_KEY,
3534
)
3635
from ._error_handlers import base_long_running_error_handler
37-
from ._manager import AiohttpLongRunningManager, get_long_running_manager
36+
from ._manager import (
37+
APP_LONG_RUNNING_MANAGER_APPKEY,
38+
AiohttpLongRunningManager,
39+
get_long_running_manager,
40+
)
3841

3942

4043
def _no_ops_decorator(handler: Handler):
@@ -178,7 +181,7 @@ async def on_cleanup_ctx(app: web.Application) -> AsyncGenerator[None, None]:
178181
app.middlewares.append(base_long_running_error_handler)
179182

180183
# add components to state
181-
app[APP_LONG_RUNNING_MANAGER_KEY] = long_running_manager = (
184+
app[APP_LONG_RUNNING_MANAGER_APPKEY] = long_running_manager = (
182185
AiohttpLongRunningManager(
183186
stale_task_check_interval=stale_task_check_interval,
184187
stale_task_detect_timeout=stale_task_detect_timeout,

0 commit comments

Comments
 (0)