simplify throttle

This commit is contained in:
Matthias 2022-10-23 14:51:17 +02:00
parent d0571464db
commit 10090a36d5

View File

@ -35,7 +35,6 @@ class Worker:
self._config = config
self._init(False)
self.last_throttle_start_time: float = 0
self._heartbeat_msg: float = 0
# Tell systemd that we completed initialization phase
@ -135,10 +134,10 @@ class Worker:
:param throttle_secs: throttling interation execution time limit in seconds
:return: Any (result of execution of func)
"""
self.last_throttle_start_time = time.time()
last_throttle_start_time = time.time()
logger.debug("========================================")
result = func(*args, **kwargs)
time_passed = time.time() - self.last_throttle_start_time
time_passed = time.time() - last_throttle_start_time
sleep_duration = max(throttle_secs - time_passed, 0.0)
logger.debug(f"Throttling with '{func.__name__}()': sleep for {sleep_duration:.2f} s, "
f"last iteration took {time_passed:.2f} s.")