From 7b320c4b269ceea4d6ee9557d71cceaf09972463 Mon Sep 17 00:00:00 2001 From: arik Date: Sun, 16 Apr 2023 19:42:51 +0300 Subject: [PATCH] fix scheduler bug (#831) --- src/robusta/core/schedule/scheduler.py | 7 ++++--- src/robusta/integrations/scheduled/trigger.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/robusta/core/schedule/scheduler.py b/src/robusta/core/schedule/scheduler.py index 06c46ca87..8e101cc52 100644 --- a/src/robusta/core/schedule/scheduler.py +++ b/src/robusta/core/schedule/scheduler.py @@ -124,9 +124,9 @@ def __remove_scheduler_job(self, job_id): def __is_job_done(self, job: ScheduledJob) -> bool: if isinstance(job.scheduling_params, DynamicDelayRepeat): - return job.state.exec_count == len(job.scheduling_params.delay_periods) + return job.state.exec_count >= len(job.scheduling_params.delay_periods) else: # default, FIXED_DELAY_REPEAT - return job.state.exec_count == job.scheduling_params.repeat + return job.state.exec_count >= job.scheduling_params.repeat def __calc_job_delay_for_next_run(self, job: ScheduledJob): if job.state.job_status == JobStatus.NEW: @@ -136,7 +136,8 @@ def __calc_job_delay_for_next_run(self, job: ScheduledJob): return INITIAL_SCHEDULE_DELAY_SEC if isinstance(job.scheduling_params, DynamicDelayRepeat): - next_delay = job.scheduling_params.delay_periods[job.state.exec_count] + next_delay_idx = min(job.state.exec_count, len(job.scheduling_params.delay_periods) - 1) + next_delay = job.scheduling_params.delay_periods[next_delay_idx] else: # FIXED_DELAY_REPEAT type next_delay = job.scheduling_params.seconds_delay diff --git a/src/robusta/integrations/scheduled/trigger.py b/src/robusta/integrations/scheduled/trigger.py index 18d88c58b..62d56b604 100644 --- a/src/robusta/integrations/scheduled/trigger.py +++ b/src/robusta/integrations/scheduled/trigger.py @@ -31,14 +31,14 @@ def get_params(self) -> Union[FixedDelayRepeat, DynamicDelayRepeat]: class FixedDelayRepeatTrigger(ScheduledTrigger): - fixed_delay_repeat: Optional[FixedDelayRepeat] + fixed_delay_repeat: FixedDelayRepeat def get_params(self) -> Union[FixedDelayRepeat, DynamicDelayRepeat]: return self.fixed_delay_repeat class DynamicDelayRepeatTrigger(ScheduledTrigger): - dynamic_delay_repeat: Optional[DynamicDelayRepeat] + dynamic_delay_repeat: DynamicDelayRepeat def get_params(self) -> Union[FixedDelayRepeat, DynamicDelayRepeat]: return self.dynamic_delay_repeat