summaryrefslogtreecommitdiff
path: root/mirrors/utils.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-09-23 10:33:32 -0500
committerDan McGee <dan@archlinux.org>2010-09-24 19:39:36 -0500
commit10fca8281663d45c08367f9d5e351c66b670d773 (patch)
tree37c55a3c550f7397073c228380f6f8f17ad123be /mirrors/utils.py
parente82e953aa297f1e54d0aff9b2097aaab6d58d0ba (diff)
Give more information about mirror check runs and frequency
Show how many times the check has ran in the last 24 hours, as well as the average interval between checks. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'mirrors/utils.py')
-rw-r--r--mirrors/utils.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/mirrors/utils.py b/mirrors/utils.py
index 69909dcf..cdb705b2 100644
--- a/mirrors/utils.py
+++ b/mirrors/utils.py
@@ -5,10 +5,11 @@ from .models import MirrorLog, MirrorProtocol, MirrorUrl
import datetime
+default_cutoff = datetime.timedelta(hours=24)
@cache_function(300)
-def get_mirror_statuses():
- cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(hours=24)
+def get_mirror_statuses(cutoff=default_cutoff):
+ cutoff_time = datetime.datetime.utcnow() - cutoff
protocols = MirrorProtocol.objects.exclude(protocol__iexact='rsync')
# I swear, this actually has decent performance...
urls = MirrorUrl.objects.select_related('mirror', 'protocol').filter(
@@ -41,11 +42,29 @@ def get_mirror_statuses():
else:
url.delay = None
url.score = None
- return urls
+
+ if urls:
+ last_check = max([u.last_check for u in urls])
+ num_checks = max([u.check_count for u in urls])
+ check_info = MirrorLog.objects.filter(
+ check_time__gte=cutoff_time).aggregate(
+ mn=Min('check_time'), mx=Max('check_time'))
+ check_frequency = (check_info['mx'] - check_info['mn']) / num_checks
+ else:
+ last_check = None
+ num_checks = 0
+ check_frequency = None
+
+ return {
+ 'last_check': last_check,
+ 'num_checks': num_checks,
+ 'check_frequency': check_frequency,
+ 'urls': urls,
+ }
@cache_function(300)
-def get_mirror_errors():
- cutoff_time = datetime.datetime.utcnow() - datetime.timedelta(hours=24)
+def get_mirror_errors(cutoff=default_cutoff):
+ cutoff_time = datetime.datetime.utcnow() - cutoff
errors = MirrorLog.objects.filter(
is_success=False, check_time__gte=cutoff_time,
url__mirror__active=True, url__mirror__public=True).values(