Skip to content

Commit 01f08e3

Browse files
committed
@bisgaard-itis review: check if decorated
1 parent 04f77e7 commit 01f08e3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/service-library/src/servicelib/background_task_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def _decorator(
5454
async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
5555
return await coro(*args, **kwargs)
5656

57+
# Marks with an identifier (mostly to assert a function has been decorated with this decorator)
58+
setattr(_wrapper, "__exclusive_periodic__", True) # noqa: B010
5759
return _wrapper
5860

5961
return _decorator

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create_task_name(coro: Callable) -> str:
2121

2222
async def periodic_task_lifespan(
2323
app: web.Application,
24-
periodic_task_coro: Callable[[], Coroutine[None, None, None]],
24+
periodic_async_func: Callable[[], Coroutine[None, None, None]],
2525
*,
2626
task_name: str | None = None,
2727
) -> AsyncIterator[None]:
@@ -30,13 +30,15 @@ async def periodic_task_lifespan(
3030
3131
Args:
3232
app: The aiohttp web application
33-
periodic_task_coro: The periodic task coroutine function (already decorated with @exclusive_periodic)
33+
periodic_async_func: The periodic coroutine function (already decorated with @exclusive_periodic)
3434
"""
35+
assert getattr(periodic_async_func, "__exclusive_periodic__", False) # nosec
36+
3537
# setup
36-
task_name = task_name or create_task_name(periodic_task_coro)
38+
task_name = task_name or create_task_name(periodic_async_func)
3739

3840
task = asyncio.create_task(
39-
periodic_task_coro(),
41+
periodic_async_func(),
4042
name=task_name,
4143
)
4244

0 commit comments

Comments
 (0)