1010from pydantic import NonNegativeFloat , NonNegativeInt
1111from servicelib .async_utils import cancel_wait_task
1212from servicelib .background_task_utils import exclusive_periodic
13- from servicelib .redis ._client import RedisClientSDK
1413from servicelib .utils import limited_gather
1514from settings_library .redis import RedisDatabase
1615
@@ -62,10 +61,6 @@ def _can_be_removed(model: TrackedServiceModel) -> bool:
6261 return False
6362
6463
65- def _get_redis_client_from_monitor (monitor : "Monitor" ) -> RedisClientSDK :
66- return get_redis_client (monitor .app , RedisDatabase .LOCKS )
67-
68-
6964class Monitor :
7065 def __init__ (self , app : FastAPI , status_worker_interval : timedelta ) -> None :
7166 self .app = app
@@ -75,11 +70,6 @@ def __init__(self, app: FastAPI, status_worker_interval: timedelta) -> None:
7570 def status_worker_interval_seconds (self ) -> NonNegativeFloat :
7671 return self .status_worker_interval .total_seconds ()
7772
78- @exclusive_periodic (
79- _get_redis_client_from_monitor ,
80- task_interval = _INTERVAL_BETWEEN_CHECKS ,
81- retry_after = _INTERVAL_BETWEEN_CHECKS ,
82- )
8373 async def _worker_check_services_require_status_update (self ) -> None :
8474 """
8575 Check if any service requires it's status to be polled.
@@ -144,8 +134,16 @@ async def _worker_check_services_require_status_update(self) -> None:
144134 )
145135
146136 async def setup (self ) -> None :
137+ @exclusive_periodic (
138+ get_redis_client (self .app , RedisDatabase .LOCKS ),
139+ task_interval = _INTERVAL_BETWEEN_CHECKS ,
140+ retry_after = _INTERVAL_BETWEEN_CHECKS ,
141+ )
142+ async def _periodic_check_services_require_status_update () -> None :
143+ await self ._worker_check_services_require_status_update ()
144+
147145 self .app .state .status_monitor_background_task = asyncio .create_task (
148- self . _worker_check_services_require_status_update (),
146+ _periodic_check_services_require_status_update (),
149147 name = "periodic_service_status_update" ,
150148 )
151149
0 commit comments