main: display how long a mirror has been out-of-sync
This commit is contained in:
parent
660b566715
commit
9f345c7b0c
8
main.py
8
main.py
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue