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))
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)