Skip to content

Commit

Permalink
Introduce min_delay parameter for create_task.
Browse files Browse the repository at this point in the history
Set it to 1.0 for the flush_buffers task.
  • Loading branch information
vdbergh authored and ppigazzini committed Jul 1, 2024
1 parent 6d65897 commit 688e9ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion server/fishtest/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ def __init__(
period,
worker,
initial_delay=None,
min_delay=0.0,
one_shot=False,
jitter=0.0,
scheduler=None,
Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -697,6 +705,7 @@ def create_task(
period,
worker,
initial_delay=None,
min_delay=0.0,
one_shot=False,
jitter=None,
args=(),
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 688e9ce

Please sign in to comment.