summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2012-02-07 13:36:54 +0100
committerLeif Johansson <leifj@sunet.se>2012-02-07 13:36:54 +0100
commit635d92fc5ded0faec71849554224608f0424fae2 (patch)
tree667c3b0ff0cddc5b16fcd388b575c40b9a44afc5
parentcfe4ddee2dff06465bf8c66e2e793ae1cf4368d5 (diff)
refactor poll task
-rw-r--r--src/meetingtools/ac/api.py6
-rw-r--r--src/meetingtools/apps/room/tasks.py15
-rw-r--r--src/meetingtools/apps/room/views.py3
3 files changed, 17 insertions, 7 deletions
diff --git a/src/meetingtools/ac/api.py b/src/meetingtools/ac/api.py
index 0be2e6a..c17d500 100644
--- a/src/meetingtools/ac/api.py
+++ b/src/meetingtools/ac/api.py
@@ -192,9 +192,7 @@ class ACPClient():
return (user_count,host_count)
- def poll_user_counts(self,room,recheck=0):
+ def poll_user_counts(self,room):
(room.user_count,room.host_count) = self.user_counts(room.sco_id)
room.save()
- if room.user_count > 0 or recheck > 0:
- logging.debug("will recheck %d more times ..." % (recheck -1))
- send_task('meetingtools.apps.room.tasks.poll_user_counts',[room],{'recheck': recheck-1},countdown=2) \ No newline at end of file
+ return (room.user_count,room.host_count) \ No newline at end of file
diff --git a/src/meetingtools/apps/room/tasks.py b/src/meetingtools/apps/room/tasks.py
index 25876eb..7bfc92a 100644
--- a/src/meetingtools/apps/room/tasks.py
+++ b/src/meetingtools/apps/room/tasks.py
@@ -17,6 +17,7 @@ import logging
from datetime import datetime,timedelta
from lxml import etree
from django.db.models import Q
+import math
def _owner_username(api,sco):
logging.debug(sco)
@@ -131,11 +132,21 @@ def import_all_rooms():
for acc in ACCluster.objects.all():
_import_acc(acc)
+def start_user_counts_poll(room,niter):
+ poll_user_counts.apply_async(args=[room],kwargs={'niter': niter})
+
@task(name='meetingtools.apps.room.tasks.poll_user_counts',rate_limit="10/s")
-def poll_user_counts(room,recheck=0):
+def poll_user_counts(room,niter=0):
logging.debug("rechecking user_counts for room %s" % room.name)
api = ac_api_client_direct(room.acc)
- api.poll_user_counts(room,recheck)
+ (nusers,nhosts) = api.poll_user_counts(room)
+ if nusers > 0:
+ logging.debug("room occupied by %d users and %d hosts, checking again in 20 ..." % (nusers,nhosts))
+ poll_user_counts.apply_async(args=[room],kwargs={'niter': 0},countdown=20)
+ elif niter > 0:
+ logging.debug("room empty, will check again in 5 for %d more times ..." % (niter -1))
+ poll_user_counts.apply_async(args=[room],kwargs={'niter': niter-1},countdown=5)
+ return (nusers,nhosts)
# belts and suspenders - we setup polling for active rooms aswell...
@periodic_task(run_every=crontab(hour="*", minute="*/5", day_of_week="*"))
diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py
index 8ba25c2..49d8481 100644
--- a/src/meetingtools/apps/room/views.py
+++ b/src/meetingtools/apps/room/views.py
@@ -32,6 +32,7 @@ from meetingtools.apps.cluster.models import acc_for_user
from django.contrib.auth.models import User
import iso8601
from celery.execute import send_task
+from meetingtools.apps.room.tasks import start_user_counts_poll
def _user_meeting_folder(request,acc):
if not session(request,'my_meetings_sco_id'):
@@ -421,7 +422,7 @@ def _goto(request,room,clean=True,promote=False):
r = api.request('sco-info',{'sco-id':room.sco_id},True)
urlpath = r.et.findtext('.//sco/url-path')
- api.poll_user_counts(room,recheck=5)
+ start_user_counts_poll(room,10)
if key:
try:
user_client = ACPClient(room.acc.api_url, request.user.username, key, cache=False)