File tree Expand file tree Collapse file tree 4 files changed +6
-0
lines changed
tests/unit/cmk/gui/job_scheduler/background_jobs Expand file tree Collapse file tree 4 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ class BackgroundJobsHealth(BaseModel, frozen=True):
5656
5757
5858class ScheduledJobsHealth (BaseModel , frozen = True ):
59+ next_cycle_start : int
5960 running_jobs : Mapping [str , int ]
6061 job_executions : Mapping [str , int ]
6162
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ async def check_health(request: Request) -> HealthResponse:
105105 job_executions = executor .job_executions (),
106106 ),
107107 scheduled_jobs = ScheduledJobsHealth (
108+ next_cycle_start = scheduler_state .next_cycle_start ,
108109 running_jobs = {
109110 name : job .started_at
110111 for name , job in filter_running_jobs (scheduler_state .running_jobs ).items ()
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ def _run_scheduler(
6161 logger .error ("Exception in scheduler (Crash ID: %s)" , crash_msg , exc_info = True )
6262
6363 if (sleep_time := 60 - (time .time () - cycle_start )) > 0 :
64+ state .next_cycle_start = int (time .time () + sleep_time )
6465 stop_event .wait (sleep_time )
6566 finally :
6667 # The UI code does not clean up locks properly in all cases, so we need to do it here
@@ -211,5 +212,6 @@ class ScheduledJob:
211212
212213@dataclass
213214class SchedulerState :
215+ next_cycle_start : int = 0
214216 running_jobs : dict [str , ScheduledJob ] = field (default_factory = dict )
215217 job_executions : Counter [str ] = field (default_factory = Counter )
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ def _get_test_client(loaded_at: int) -> TestClient:
105105 registered_jobs = {"hello_job" : HelloJob },
106106 executor = DummyExecutor (logger ),
107107 scheduler_state = SchedulerState (
108+ next_cycle_start = 10 ,
108109 running_jobs = {
109110 "scheduled_1_running" : ScheduledJob (
110111 started_at = 123 ,
@@ -190,6 +191,7 @@ def test_health_check() -> None:
190191 )
191192 assert response .background_jobs .running_jobs == {"job_id" : 42 }
192193 assert response .background_jobs .job_executions == {"job_1" : 1 , "job_2" : 2 }
194+ assert response .scheduled_jobs .next_cycle_start == 10
193195 assert response .scheduled_jobs .running_jobs == {"scheduled_1_running" : 123 }
194196 assert response .scheduled_jobs .job_executions == {"scheduled_1" : 1 , "scheduled_2" : 2 }
195197
You can’t perform that action at this time.
0 commit comments