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):
56
56
57
57
58
58
class ScheduledJobsHealth (BaseModel , frozen = True ):
59
+ next_cycle_start : int
59
60
running_jobs : Mapping [str , int ]
60
61
job_executions : Mapping [str , int ]
61
62
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ async def check_health(request: Request) -> HealthResponse:
105
105
job_executions = executor .job_executions (),
106
106
),
107
107
scheduled_jobs = ScheduledJobsHealth (
108
+ next_cycle_start = scheduler_state .next_cycle_start ,
108
109
running_jobs = {
109
110
name : job .started_at
110
111
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(
61
61
logger .error ("Exception in scheduler (Crash ID: %s)" , crash_msg , exc_info = True )
62
62
63
63
if (sleep_time := 60 - (time .time () - cycle_start )) > 0 :
64
+ state .next_cycle_start = int (time .time () + sleep_time )
64
65
stop_event .wait (sleep_time )
65
66
finally :
66
67
# 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:
211
212
212
213
@dataclass
213
214
class SchedulerState :
215
+ next_cycle_start : int = 0
214
216
running_jobs : dict [str , ScheduledJob ] = field (default_factory = dict )
215
217
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:
105
105
registered_jobs = {"hello_job" : HelloJob },
106
106
executor = DummyExecutor (logger ),
107
107
scheduler_state = SchedulerState (
108
+ next_cycle_start = 10 ,
108
109
running_jobs = {
109
110
"scheduled_1_running" : ScheduledJob (
110
111
started_at = 123 ,
@@ -190,6 +191,7 @@ def test_health_check() -> None:
190
191
)
191
192
assert response .background_jobs .running_jobs == {"job_id" : 42 }
192
193
assert response .background_jobs .job_executions == {"job_1" : 1 , "job_2" : 2 }
194
+ assert response .scheduled_jobs .next_cycle_start == 10
193
195
assert response .scheduled_jobs .running_jobs == {"scheduled_1_running" : 123 }
194
196
assert response .scheduled_jobs .job_executions == {"scheduled_1" : 1 , "scheduled_2" : 2 }
195
197
You can’t perform that action at this time.
0 commit comments