comparison gpp/core/management/commands/max_users.py @ 423:3fe60148f75c

Fixing #203; use Redis for who's online function.
author Brian Neal <bgneal@gmail.com>
date Sat, 23 Apr 2011 19:19:38 +0000
parents dcc929973bba
children f72ace06658a
comparison
equal deleted inserted replaced
422:6309814cd6f7 423:3fe60148f75c
5 """ 5 """
6 import datetime 6 import datetime
7 7
8 from django.core.management.base import NoArgsCommand 8 from django.core.management.base import NoArgsCommand
9 9
10 from core.models import UserLastVisit, AnonLastVisit, Statistic 10 from core.models import Statistic
11 from core.whos_online import get_users_online, get_visitors_online, tick
11 12
12 13
13 class Command(NoArgsCommand): 14 class Command(NoArgsCommand):
14 help = "Run periodically to compute the max users online statistic." 15 help = "Run periodically to compute the max users online statistic."
15 16
16 def handle_noargs(self, **options): 17 def handle_noargs(self, **options):
17 18
18 now = datetime.datetime.now() 19 now = datetime.datetime.now()
19 cut_off = now - datetime.timedelta(minutes=15)
20 20
21 users = UserLastVisit.objects.filter(last_visit__gte=cut_off).count() 21 users = len(get_users_online())
22 guests = AnonLastVisit.objects.filter(last_visit__gte=cut_off).count() 22 guests = len(get_visitors_online())
23 23
24 updated = False 24 updated = False
25 try: 25 try:
26 stat = Statistic.objects.get(pk=1) 26 stat = Statistic.objects.get(pk=1)
27 except Statistic.DoesNotExist: 27 except Statistic.DoesNotExist:
40 stat.max_anon_users_date = now 40 stat.max_anon_users_date = now
41 updated=True 41 updated=True
42 42
43 if updated: 43 if updated:
44 stat.save() 44 stat.save()
45
46 # "tick" the who's online data collector
47 tick()