various mirror fixes #7

Merged
r389li merged 3 commits from y266shen/mirror-checker:feature-retry into master 2022-03-26 21:24:23 -04:00
1 changed files with 4 additions and 4 deletions
Showing only changes of commit 9f345c7b0c - Show all commits

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