diff --git a/server/fishtest/rundb.py b/server/fishtest/rundb.py index 03fe56ef0..806779462 100644 --- a/server/fishtest/rundb.py +++ b/server/fishtest/rundb.py @@ -103,7 +103,7 @@ def __init__(self, db_name="fishtest_new", port=-1, is_primary_instance=True): def schedule_tasks(self): if self.scheduler is None: self.scheduler = Scheduler(jitter=0.05) - self.scheduler.create_task(1.0, self.flush_buffers) + self.scheduler.create_task(1.0, self.flush_buffers, min_delay=1.0) self.scheduler.create_task(60.0, self.clean_cache) self.scheduler.create_task(60.0, self.scavenge_dead_tasks) self.scheduler.create_task(60.0, self.update_itp) diff --git a/server/fishtest/util.py b/server/fishtest/util.py index a85096dc0..3313c86ef 100644 --- a/server/fishtest/util.py +++ b/server/fishtest/util.py @@ -613,6 +613,7 @@ def __init__( period, worker, initial_delay=None, + min_delay=0.0, one_shot=False, jitter=0.0, scheduler=None, @@ -625,6 +626,7 @@ def __init__( initial_delay = self.period else: initial_delay = timedelta(seconds=initial_delay) + self.min_delay = timedelta(seconds=min_delay) self.__rel_jitter = jitter * self.period self.__next_schedule = ( datetime.now(timezone.utc) @@ -647,7 +649,13 @@ def _do_work(self): if not self.one_shot: jitter = uniform(-self.__rel_jitter, self.__rel_jitter) with self.__lock: - self.__next_schedule += self.period + jitter + self.__next_schedule = ( + max( + self.__next_schedule + self.period, + datetime.now(timezone.utc) + self.min_delay, + ) + + jitter + ) else: self.__expired = True @@ -697,6 +705,7 @@ def create_task( period, worker, initial_delay=None, + min_delay=0.0, one_shot=False, jitter=None, args=(), @@ -713,6 +722,9 @@ def create_task( :param initial_delay: The delay before the first execution of the task, defaults to period :type initial_delay: float, optional + :param min_delay: The minimum delay before the same task is repeated, defaults to 0.0 + :type min_delay: float, optional + :param one_shot: If true, execute the task only once, defaults to False :type one_shot: bool, optional @@ -733,6 +745,7 @@ def create_task( period, worker, initial_delay=initial_delay, + min_delay=min_delay, one_shot=one_shot, jitter=jitter, scheduler=self,