Skip to content

Commit f31912f

Browse files
committed
fixes pylint
1 parent 990972d commit f31912f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

services/web/server/src/simcore_service_webserver/garbage_collector/_tasks_core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
_logger = logging.getLogger(__name__)
2121

22+
_GC_TASK_NAME = f"{__name__}._collect_garbage_periodically"
23+
2224

2325
def create_background_task_for_garbage_collection() -> CleanupContextFunc:
2426

@@ -36,7 +38,9 @@ async def _collect_garbage_periodically() -> None:
3638
with log_context(_logger, logging.INFO, "Garbage collect cycle"):
3739
await collect_garbage(app)
3840

39-
async for _ in setup_periodic_task(app, _collect_garbage_periodically):
41+
async for _ in setup_periodic_task(
42+
app, _collect_garbage_periodically, task_name=_GC_TASK_NAME
43+
):
4044
yield
4145

4246
return _cleanup_ctx_fun

services/web/server/src/simcore_service_webserver/garbage_collector/_tasks_utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@
1111
CleanupContextFunc = Callable[[web.Application], AsyncIterator[None]]
1212

1313

14+
def create_task_name(coro: Callable) -> str:
15+
"""
16+
Returns a unique name for the task based on its module and function name.
17+
This is useful for logging and debugging purposes.
18+
"""
19+
return f"{coro.__module__}.{coro.__name__}"
20+
21+
1422
async def setup_periodic_task(
1523
app: web.Application,
1624
periodic_task_coro: Callable[[], Coroutine[None, None, None]],
25+
*,
26+
task_name: str | None = None,
1727
) -> AsyncIterator[None]:
1828
"""
1929
Generic setup and teardown for periodic background tasks.
@@ -23,15 +33,15 @@ async def setup_periodic_task(
2333
periodic_task_coro: The periodic task coroutine function (already decorated with @exclusive_periodic)
2434
"""
2535
# setup
26-
task_name = f"{periodic_task_coro.__module__}.{periodic_task_coro.__name__}"
36+
task_name = task_name or create_task_name(periodic_task_coro)
2737

2838
task = asyncio.create_task(
2939
periodic_task_coro(),
3040
name=task_name,
3141
)
3242

3343
# prevents premature garbage collection of the task
34-
app_task_key = f"tasks.{task_name}"
44+
app_task_key = f"gc-tasks/{task_name}"
3545
if app_task_key in app:
3646
msg = f"Task {task_name} is already registered in the app state"
3747
raise ValueError(msg)

0 commit comments

Comments
 (0)