From: Julien Cristau Date: Sun, 1 Oct 2017 10:28:56 +0000 (+0200) Subject: mirror-health: move up-to-date check to a function X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=dc142e05682ed2976e677b5b08f5d623cf9136fd;p=mirror%2Fdsa-puppet.git mirror-health: move up-to-date check to a function --- diff --git a/modules/roles/files/mirror_health/mirror-health b/modules/roles/files/mirror_health/mirror-health index ed87f5664..1d4fae0e3 100755 --- a/modules/roles/files/mirror_health/mirror-health +++ b/modules/roles/files/mirror_health/mirror-health @@ -29,8 +29,8 @@ def last_modified(response): lm = calendar.timegm(parsedate(response.headers['last-modified'])) return lm -while True: - start = time.time() +def check_uptodate(): + global latest_ts for host in HOSTS: try: lm = last_modified(retrieve_from_host(host, URL)) @@ -42,14 +42,20 @@ while True: local_lm = last_modified(retrieve_from_host('localhost', URL)) logging.debug("lm for localhost: %s", local_lm) if local_lm < latest_ts: + logging.info("considering myself unhealthy my ts=%s latest_ts=%s", local_lm, latest_ts) + return False + return True + +while True: + start = time.time() + if check_uptodate(): + logging.info("considering myself healthy") + open(HEALTH_FILE, 'w').write("OK") + else: try: - logging.info("considering myself unhealthy my ts=%s latest_ts=%s", local_lm, latest_ts) os.remove(HEALTH_FILE) except OSError: pass - else: - logging.info("considering myself healthy") - open(HEALTH_FILE, 'w').write("OK") sleep_time = start + INTERVAL - time.time() logging.debug("sleeping for %d seconds", sleep_time) time.sleep(sleep_time)