summaryrefslogtreecommitdiff
path: root/src/meetingtools/apps/room
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 /src/meetingtools/apps/room
parentcfe4ddee2dff06465bf8c66e2e793ae1cf4368d5 (diff)
refactor poll task
Diffstat (limited to 'src/meetingtools/apps/room')
-rw-r--r--src/meetingtools/apps/room/tasks.py15
-rw-r--r--src/meetingtools/apps/room/views.py3
2 files changed, 15 insertions, 3 deletions
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)