summaryrefslogtreecommitdiff
path: root/meetingtools/apps/stats
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2012-11-07 16:29:28 +0100
committerLeif Johansson <leifj@sunet.se>2012-11-07 16:29:28 +0100
commit81bbd611fa82f26c201ee2d0b12f8aece25019bd (patch)
tree8893d2050a114b86e311d4e3811fb013201760db /meetingtools/apps/stats
parentf3a48403ef9270a33e8844230e85134f966431d6 (diff)
updated tasks w more loggin
Diffstat (limited to 'meetingtools/apps/stats')
-rw-r--r--meetingtools/apps/stats/tasks.py26
1 files changed, 21 insertions, 5 deletions
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)