summaryrefslogtreecommitdiff
path: root/src/meetingtools/apps/room/tasks.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/meetingtools/apps/room/tasks.py')
-rw-r--r--src/meetingtools/apps/room/tasks.py54
1 files changed, 26 insertions, 28 deletions
diff --git a/src/meetingtools/apps/room/tasks.py b/src/meetingtools/apps/room/tasks.py
index 7bfc92a..aea6b3b 100644
--- a/src/meetingtools/apps/room/tasks.py
+++ b/src/meetingtools/apps/room/tasks.py
@@ -6,8 +6,7 @@ Created on Jan 18, 2012
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,\
- ac_api_client_direct
+from meetingtools.ac import ac_api_client
from meetingtools.apps.room.models import Room
import iso8601
from django.contrib.auth.models import User
@@ -17,7 +16,6 @@ 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)
@@ -87,11 +85,12 @@ def _import_one_room(acc,api,row):
lastupdated = None
if room:
lastupdated = room.lastupdated.replace(tzinfo=None) # make the compare work - very ugly
- logging.debug("last %s" % last)
- logging.debug("lastupdated %s" % lastupdated)
+
+ #logging.debug("last %s" % last)
+ #logging.debug("lastupdated %s" % lastupdated)
if not room or lastupdated < last:
(r,username) = _extended_info(api, sco_id)
- logging.debug("owner: %s" % username)
+ logging.debug("found room owned by %s time for and update" % username)
if username is None:
return
@@ -119,15 +118,14 @@ def _import_one_room(acc,api,row):
room.unlock()
def _import_acc(acc):
- api = ac_api_client_direct(acc)
- backthen = datetime.now()-timedelta(seconds=6000000)
- backthen = backthen.replace(microsecond=0)
- logging.debug(backthen.isoformat())
- r = api.request('report-bulk-objects',{'filter-type': 'meeting','filter-gt-date-modified': backthen.isoformat()})
- for row in r.et.xpath("//row"):
- _import_one_room(acc,api,row)
+ with ac_api_client(acc) as api:
+ then = datetime.now()-timedelta(seconds=3600)
+ then = then.replace(microsecond=0)
+ r = api.request('report-bulk-objects',{'filter-type': 'meeting','filter-gt-date-modified': then.isoformat()})
+ for row in r.et.xpath("//row"):
+ _import_one_room(acc,api,row)
-@periodic_task(run_every=crontab(hour="*", minute="*/1", day_of_week="*"))
+@periodic_task(run_every=crontab(hour="*", minute="*/5", day_of_week="*"))
def import_all_rooms():
for acc in ACCluster.objects.all():
_import_acc(acc)
@@ -137,22 +135,22 @@ def start_user_counts_poll(room,niter):
@task(name='meetingtools.apps.room.tasks.poll_user_counts',rate_limit="10/s")
def poll_user_counts(room,niter=0):
- logging.debug("rechecking user_counts for room %s" % room.name)
- api = ac_api_client_direct(room.acc)
- (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)
+ logging.debug("polling user_counts for room %s" % room.name)
+ with ac_api_client(room.acc) as api:
+ (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="*"))
def import_recent_user_counts():
for acc in ACCluster.objects.all():
- 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
+ with ac_api_client(acc) as api:
+ 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