Author: croberts
Date: 2012-05-31 16:42:28 +0000 (Thu, 31 May 2012)
New Revision: 5396
Modified:
trunk/mint/python/mint/plumage/session.py
Log:
Making the cumin-report historical record loading thread wake-up once each day to handle
the case of a backload of older records (database recovery, etc).
Modified: trunk/mint/python/mint/plumage/session.py
===================================================================
--- trunk/mint/python/mint/plumage/session.py 2012-05-31 14:49:15 UTC (rev 5395)
+++ trunk/mint/python/mint/plumage/session.py 2012-05-31 16:42:28 UTC (rev 5396)
@@ -209,37 +209,40 @@
return record
def run(self):
- self._check_connection()
- if self.stop_requested:
- return
-
- try:
- # Make sure we have a database
- self._init()
-
- # We create objects here. Tag them with the right class,
- # probably specified to us from a config option (with a corresponding
- # query specification in the xml)
- (oldest, newest) =
self.app.update_thread.get_first_and_last_sample_timestamp(self.cls)
- if oldest is None:
- # if we have no oldest record (first run), start at "5 min ago"
and start loading everything
- oldest = datetime.now() - timedelta(seconds=300)
- oldest = oldest + UTC_DIFF
-
- log.info("PlumageSessionThread--history: Loading records older than
%s" % oldest)
- times = sorted(self.collection.find({"ts": {'$lt':
oldest}}).distinct('ts'), reverse=True)
- sample_times = map(lambda i: times[i],filter(lambda i: i%5 ==
0,range(len(times))))
-
- for time in sample_times:
- record = self.fillOSUtilStats(time, "history")
-
- obj = ObjectUpdate(self.app.model, record, self.cls)
- self.app.update_thread.enqueue(obj)
-
- log.info("PlumageSessionThread--history: run completed")
-
- except Exception, e:
- log.info("%s got exception %s, exiting" % (self.__class__.__name__,
str(e)))
+ while True:
+ self._check_connection()
+ if self.stop_requested:
+ return
+
+ try:
+ # Make sure we have a database
+ self._init()
+
+ # We create objects here. Tag them with the right class,
+ # probably specified to us from a config option (with a corresponding
+ # query specification in the xml)
+ (oldest, newest) =
self.app.update_thread.get_first_and_last_sample_timestamp(self.cls)
+ if oldest is None:
+ # if we have no oldest record (first run), start at "5 min
ago" and start loading everything
+ oldest = datetime.now() - timedelta(seconds=300)
+ oldest = oldest + UTC_DIFF
+
+ log.info("PlumageSessionThread--history: Loading records older than
%s" % oldest)
+ times = sorted(self.collection.find({"ts": {'$lt':
oldest}}).distinct('ts'), reverse=True)
+ sample_times = map(lambda i: times[i],filter(lambda i: i%5 ==
0,range(len(times))))
+
+ for time in sample_times:
+ record = self.fillOSUtilStats(time, "history")
+
+ obj = ObjectUpdate(self.app.model, record, self.cls)
+ self.app.update_thread.enqueue(obj)
+
+ log.info("PlumageSessionThread--history: run completed")
+
+ except Exception, e:
+ log.info("%s got exception %s, exiting" %
(self.__class__.__name__, str(e)))
+ #wake up once a day just in case there has been additional historical items
added
+ sleep(86400)
class CurrentPlumageSessionThread(PlumageSessionThread):
def run(self):
Show replies by date