diff options
Diffstat (limited to 'meetingtools')
-rw-r--r-- | meetingtools/apps/room/tasks.py | 15 | ||||
-rw-r--r-- | meetingtools/apps/stats/tasks.py | 26 |
2 files changed, 33 insertions, 8 deletions
diff --git a/meetingtools/apps/room/tasks.py b/meetingtools/apps/room/tasks.py index dca053c..f491afc 100644 --- a/meetingtools/apps/room/tasks.py +++ b/meetingtools/apps/room/tasks.py @@ -164,16 +164,22 @@ def import_acc(acc,since=0): else: r = api.request('report-bulk-objects',{'filter-type': 'meeting'}) + nr = 0 + ne = 0 for row in r.et.xpath("//row"): try: _import_one_room(acc,api,row) + nr += 1 except Exception,ex: logging.error(ex) + ne += 1 + + logging.info("%s: Imported %d rooms and got %d errors" % (acc,nr,ne)) @periodic_task(run_every=crontab(hour="*", minute="*", day_of_week="*")) def import_all_rooms(): for acc in ACCluster.objects.all(): - import_acc(acc,since=3600) + import_acc(acc,since=3700) def start_user_counts_poll(room,niter): poll_user_counts.apply_async(args=[room],kwargs={'niter': niter}) @@ -196,12 +202,15 @@ def poll_user_counts(room,niter=0): def import_recent_user_counts(): for acc in ACCluster.objects.all(): with ac_api_client(acc) as api: + nr = 0 then = datetime.now()-timedelta(seconds=600) for room in Room.objects.filter((Q(lastupdated__gt=then) | Q(lastvisited__gt=then)) & Q(sco__acc=acc)): api.poll_user_counts(room) - + nr += 1 + logging.info("%s: Checked usage for %d rooms since %s" % (acc,nr,then)) + # look for sessions that are newer than the one we know about for a room -@periodic_task(run_every=crontab(hour="*", minute="*/5", day_of_week="*")) +#@periodic_task(run_every=crontab(hour="*", minute="*/5", day_of_week="*")) def import_sessions(): for room in Room.objects.all(): with ac_api_client(room.sco.acc) as api: diff --git a/meetingtools/apps/stats/tasks.py b/meetingtools/apps/stats/tasks.py index fb4b5c7..ecd2280 100644 --- a/meetingtools/apps/stats/tasks.py +++ b/meetingtools/apps/stats/tasks.py @@ -1,6 +1,7 @@ import logging from celery.schedules import crontab from celery.task import periodic_task +from apps.room.models import Room from meetingtools.ac import ac_api_client from meetingtools.apps.cluster.models import ACCluster from datetime import datetime,timedelta @@ -8,7 +9,7 @@ from meetingtools.apps.stats.models import UserMeetingTransaction __author__ = 'leifj' -def import_acc_sessions(acc,since=0): +def import_acc_sessions(acc,since=0,room_last_visited=False): with ac_api_client(acc) as api: p = {'sort': 'asc','sort1': 'date-created','filter-type': 'meeting'} @@ -21,13 +22,28 @@ def import_acc_sessions(acc,since=0): p['filter-gte-date-created'] = begin.isoformat() r = api.request('report-bulk-consolidated-transactions',p,True) + nr = 0 + ne = 0 for tx in r.et.findall(".//row"): try: - UserMeetingTransaction.create(acc,tx) + tx = UserMeetingTransaction.create(acc,tx) + if room_last_visited: + rooms = Room.objects.filter(sco=tx.sco) + if len(rooms) == 1: + room = rooms[0] + if room.lastvisited is None or room.lastvisited < tx.date_closed: + room.lastvisited = tx.date_created + room.save() + nr += 1 except Exception,ex: logging.error(ex) + ne += 1 + logging.info("%s: Imported %d transactions with %d errors" % (acc,nr,ne)) -@periodic_task(run_every=crontab(hour="*", minute="*", day_of_week="*")) -def import_sessions(since=3700): +def import_sessions(since,room_last_visited=False): for acc in ACCluster.objects.all(): - import_acc_sessions(acc,since)
\ No newline at end of file + import_acc_sessions(acc,since,room_last_visited) + +@periodic_task(run_every=crontab(hour="*", minute="*/5", day_of_week="*")) +def _hourly_import(): + import_sessions(600,True) |