From 2e299273e2462775cf3ecd4f93715678575319fd Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 7 Oct 2010 08:07:03 -0500 Subject: mirrorcheck: record duration on file not found errors On an HTTP 404, FTP 550, or inability to parse the lastsync file, record the duration of the check even though we couldn't get a time from the mirror. This allows for these checks to show up as completed but in error, which is more what. Previously, inability to parse the date was also recorded as a success, so change that to be a failure and record an error message with it. Signed-off-by: Dan McGee --- mirrors/management/commands/mirrorcheck.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mirrors/management/commands/mirrorcheck.py b/mirrors/management/commands/mirrorcheck.py index 1662b15c..210505fa 100644 --- a/mirrors/management/commands/mirrorcheck.py +++ b/mirrors/management/commands/mirrorcheck.py @@ -20,6 +20,7 @@ import time import thread from threading import Thread +import types from Queue import Queue, Empty import urllib2 @@ -81,6 +82,7 @@ def check_mirror_url(mirror_url): # lastsync should be an epoch value, but some mirrors # are creating their own in RFC-3339 format: # '2010-09-02 11:05:06+02:00' + parsed_time = None try: parsed_time = datetime.utcfromtimestamp(int(data)) except ValueError: @@ -91,15 +93,28 @@ def check_mirror_url(mirror_url): parsed_time = parse_rfc3339_datetime(data) log.last_sync = parsed_time + # if we couldn't parse a time, this is a failure + if parsed_time == None: + log.error = "Could not parse time from lastsync" + log.is_success = False log.duration = end - start logger.debug("success: %s, %.2f" % (url, log.duration)) except urllib2.HTTPError, e: + if e.code == 404: + # we have a duration, just not a success + end = time.time() + log.duration = end - start log.is_success = False - log.error =str(e) + log.error = str(e) logger.debug("failed: %s, %s" % (url, log.error)) except urllib2.URLError, e: log.is_success=False log.error = e.reason + if isinstance(e.reason, types.StringTypes) and \ + re.search(r'550.*No such file', e.reason): + # similar to 404 case above, still record duration + end = time.time() + log.duration = end - start if isinstance(e.reason, socket.timeout): log.error = "Connection timed out." elif isinstance(e.reason, socket.error): -- cgit v1.2.3-54-g00ecf