File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ class CleanupTask:
2525
2626 Der Loop führt beim Start sofort einen ersten Run durch, danach in ``interval``-Abständen.
2727 Exceptions in _run_once werden geloggt und der Loop läuft weiter (fail-soft).
28+
29+ Single-Use: nach stop() kann die Instanz nicht restartet werden.
30+ Lifespan startet eine neue Instanz beim App-Startup.
2831 """
2932
3033 def __init__ (
@@ -56,9 +59,12 @@ async def stop(self, timeout_s: float = 5.0) -> None:
5659 if self ._task is not None :
5760 try :
5861 await asyncio .wait_for (self ._task , timeout = timeout_s )
59- except asyncio . TimeoutError :
62+ except TimeoutError :
6063 self ._task .cancel ()
61- logger .warning ("CleanupTask hat sich nicht in %ss beendet, Task gecancelled" , timeout_s )
64+ logger .warning (
65+ "CleanupTask hat sich nicht in %ss beendet, Task gecancelled" ,
66+ timeout_s ,
67+ )
6268 self ._task = None
6369
6470 async def _loop (self ) -> None :
@@ -70,7 +76,7 @@ async def _loop(self) -> None:
7076 self ._stopping .wait (),
7177 timeout = self ._interval .total_seconds (),
7278 )
73- except asyncio . TimeoutError :
79+ except TimeoutError :
7480 await self ._run_once ()
7581
7682 async def _run_once (self ) -> None :
Original file line number Diff line number Diff line change 22
33from __future__ import annotations
44
5- import asyncio
65from datetime import timedelta
76from unittest .mock import AsyncMock
87
1110
1211
1312@pytest .mark .asyncio
14- async def test_cleanup_validates_retention_days ():
13+ async def test_cleanup_validates_retention_days () -> None :
1514 store = AsyncMock ()
1615 with pytest .raises (ValueError , match = "retention_days must be >= 1" ):
1716 CleanupTask (store = store , retention_days = 0 )
1817
1918
2019@pytest .mark .asyncio
21- async def test_cleanup_initial_run_on_start ():
20+ async def test_cleanup_initial_run_on_start () -> None :
2221 store = AsyncMock ()
2322 store .evict_terminal_older_than .return_value = 3
2423 task = CleanupTask (store = store , retention_days = 30 , interval = timedelta (seconds = 99 ))
@@ -33,7 +32,7 @@ async def test_cleanup_initial_run_on_start():
3332
3433
3534@pytest .mark .asyncio
36- async def test_cleanup_fail_soft_on_exception ():
35+ async def test_cleanup_fail_soft_on_exception () -> None :
3736 store = AsyncMock ()
3837 store .evict_terminal_older_than .side_effect = RuntimeError ("boom" )
3938 task = CleanupTask (store = store , retention_days = 30 , interval = timedelta (seconds = 99 ))
You can’t perform that action at this time.
0 commit comments