diff options
Diffstat (limited to 'src/meetingtools/apps/room/tasks.py')
-rw-r--r-- | src/meetingtools/apps/room/tasks.py | 56 |
1 files changed, 17 insertions, 39 deletions
diff --git a/src/meetingtools/apps/room/tasks.py b/src/meetingtools/apps/room/tasks.py index 0d638a6..25876eb 100644 --- a/src/meetingtools/apps/room/tasks.py +++ b/src/meetingtools/apps/room/tasks.py @@ -3,7 +3,7 @@ Created on Jan 18, 2012 @author: leifj ''' -from celery.task import periodic_task +from celery.task import periodic_task,task from celery.schedules import crontab from meetingtools.apps.cluster.models import ACCluster from meetingtools.ac import ac_api_client, ac_api_client_nocache,\ @@ -16,6 +16,7 @@ from django.core.exceptions import ObjectDoesNotExist import logging from datetime import datetime,timedelta from lxml import etree +from django.db.models import Q def _owner_username(api,sco): logging.debug(sco) @@ -110,12 +111,7 @@ def _import_one_room(acc,api,row): room.source_sco_id = source_sco_id room.description = description room.urlpath = urlpath - - userlist = api.request('meeting-usermanager-user-list',{'sco-id': room.sco_id},False) - if userlist.status_code() == 'ok': - room.user_count = int(userlist.et.xpath("count(.//userdetails)")) - room.host_count = int(userlist.et.xpath("count(.//userdetails/role[text() = 'host'])")) - + room.save() room.unlock() else: @@ -130,40 +126,22 @@ def _import_acc(acc): for row in r.et.xpath("//row"): _import_one_room(acc,api,row) - @periodic_task(run_every=crontab(hour="*", minute="*/1", day_of_week="*")) def import_all_rooms(): for acc in ACCluster.objects.all(): _import_acc(acc) - -def _import_meeting_room_usercount(api,acc,sco_id,row=None,room=None): - try: - if room == None: - room = Room.objects.get(acc=acc,sco_id=sco_id) - - if row and row.findtext("date-end"): - room.user_count = 0 - room.host_count = 0 - else: - userlist = api.request('meeting-usermanager-user-list',{'sco-id': room.sco_id},False) - if userlist.status_code() == 'ok': - room.user_count = int(userlist.et.xpath("count(.//userdetails)")) - room.host_count = int(userlist.et.xpath("count(.//userdetails/role[text() = 'host'])")) - elif userlist.status_code() == 'no-access' and userlist.subcode() == 'not-available': #no active session - room.user_count = 0 - room.host_count = 0 - room.save() - except ObjectDoesNotExist: - pass - -def _import_user_counts_acc(acc): - api = ac_api_client_direct(acc) - for room in Room.objects.filter(acc=acc,user_count=None): - _import_meeting_room_usercount(api,acc,room.sco_id,None,room) - for room in Room.objects.filter(acc=acc,user_count__gt=0): - _import_meeting_room_usercount(api,acc,room.sco_id,None,room) - -@periodic_task(run_every=crontab(hour="*", minute="*/1", day_of_week="*")) -def import_user_counts(): + +@task(name='meetingtools.apps.room.tasks.poll_user_counts',rate_limit="10/s") +def poll_user_counts(room,recheck=0): + logging.debug("rechecking user_counts for room %s" % room.name) + api = ac_api_client_direct(room.acc) + api.poll_user_counts(room,recheck) + +# belts and suspenders - we setup polling for active rooms aswell... +@periodic_task(run_every=crontab(hour="*", minute="*/5", day_of_week="*")) +def import_recent_user_counts(): for acc in ACCluster.objects.all(): - _import_user_counts_acc(acc)
\ No newline at end of file + api = ac_api_client_direct(acc) + then = datetime.now()-timedelta(seconds=600) + for room in Room.objects.filter((Q(lastupdated__gt=then) | Q(lastvisited__gt=then)) & Q(acc=acc)): + api.poll_user_counts(room)
\ No newline at end of file |