Skip to content

Commit

Permalink
Run housekeeping during long sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
reidsunderland authored and petersilva committed Mar 11, 2024
1 parent 491a6ca commit 6426fd8
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions sarracenia/flow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ def _runCallbackMetrics(self):
logger.error( f'flowCallback plugin {p}/metricsReport crashed: {ex}' )
logger.debug( "details:", exc_info=True )

def _runHousekeeping(self, now) -> float:
""" Run housekeeping callbacks
Return the time when housekeeping should be run next
"""
logger.info(f'on_housekeeping pid: {os.getpid()} {self.o.component}/{self.o.config} instance: {self.o.no}')
self.runCallbacksTime('on_housekeeping')
self.metricsFlowReset()
self.metrics['flow']['last_housekeeping'] = now

next_housekeeping = now + self.o.housekeeping
self.metrics['flow']['next_housekeeping'] = next_housekeeping
return next_housekeeping

def has_vip(self) -> list:
"""
Expand Down Expand Up @@ -627,15 +639,7 @@ def run(self):

# Run housekeeping based on time, and before stopping to ensure it's run at least once
if now > next_housekeeping or stopping:
logger.info(
f'on_housekeeping pid: {os.getpid()} {self.o.component}/{self.o.config} instance: {self.o.no}'
)
self.runCallbacksTime('on_housekeeping')
self.metricsFlowReset()
self.metrics['flow']['last_housekeeping'] = now

next_housekeeping = now + self.o.housekeeping
self.metrics['flow']['next_housekeeping'] = next_housekeeping
next_housekeeping = self._runHousekeeping(now)

if (self.o.messageRateMin > 0) and (current_rate <
self.o.messageRateMin):
Expand Down Expand Up @@ -678,6 +682,10 @@ def run(self):
break
else:
stime -= 5
# Run housekeeping during long sleeps
now_for_hk = nowflt()
if now_for_hk > next_housekeeping:
next_housekeeping = self._runHousekeeping(now_for_hk)

last_time = now

Expand Down

0 comments on commit 6426fd8

Please sign in to comment.