Commit dbde7a3f authored by Vincent Pelletier's avatar Vincent Pelletier

caucase.utils: Fix support for host computer suspension in "until".

Break requested sleep period into smaller chunks, to try to compensate for
extended suspension periods.
The chosen values seem to be a reasonable trade-off between accuracy and
number of wake-ups.
parent 3750b5c2
Pipeline #18973 passed with stage
in 0 seconds
......@@ -717,10 +717,32 @@ def until(deadline): # pragma: no cover
"""
Call interruptibleSleep until deadline is reached.
"""
now = datetime.datetime.utcnow()
while now < deadline:
interruptibleSleep((deadline - now).total_seconds())
now = datetime.datetime.utcnow()
try:
while True:
now = datetime.datetime.utcnow()
remaining_time = (deadline - now).total_seconds()
if remaining_time <= 0:
break
# Wake up half-way to the deadline, to re-evaluate the time left: the
# computer may have been suspended, or had its time changed.
# ...but do not sleep less than 10 minutes.
# ...but do not sleep past the deadline.
# Simulating a computer suspended 75% of the time (continuously, which is
# a big approximation of the actual discrete nature of suspend periods)
# shows this approach should lead to 5 wakeups for a deadline initially
# 7 days away: first wakeup after 6.1 days, second 18 hours later, then
# 2 hours, then 17 minutes and finally the few remaining seconds.
interruptibleSleep(
max(
remaining_time / 2,
min(
remaining_time,
600,
),
),
)
except KeyboardInterrupt:
raise SleepInterrupt
return now
def log_exception(error_file, exc_info, client_address):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment