main: display how long a mirror has been out-of-sync

This commit is contained in:
Yiao Shen 2022-03-26 21:06:23 -04:00
parent 660b566715
commit 9f345c7b0c
Signed by: y266shen
GPG Key ID: D126FA196DA0F362
1 changed files with 4 additions and 4 deletions

View File

@ -18,8 +18,6 @@ NUM_THREAD = 16
MAX_RETRY = 3
RETRY_TIMEOUT = 30 # In seconds
current_time = int(time.time())
def safe_print(*args, **kwargs):
# When run with 'chronic' and 'timeout', stdout gets suppressed
# due to buffering. Make sure to always flush the output.
@ -27,6 +25,7 @@ def safe_print(*args, **kwargs):
# Return None if no error occurs and a string for error message otherwise
def check_project(args) -> Optional[str]:
current_time = int(time.time())
project, data = args
try:
project_class = getattr(sys.modules[__name__], project)
@ -43,8 +42,9 @@ def check_project(args) -> Optional[str]:
elif (data[project]["out_of_sync_since"] is not None
and current_time - data[project]["out_of_sync_since"] > data[project]["out_of_sync_interval"]):
time_str = strftime("%d %b %Y %H:%M:%S (local time)", localtime())
return f"{project} out-of-sync at {time_str}"
now_str = strftime("%d %b %Y %H:%M:%S (local time)", localtime())
duration = current_time - data[project]["out_of_sync_since"]
return f"{project} out-of-sync at {now_str} for {duration}s"
else:
data[project]["out_of_sync_since"] = current_time