[CalendarServer-changes] [12809] CalendarServer/trunk/calendarserver/webadmin/work.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 4 20:40:36 PST 2014


Revision: 12809
          http://trac.calendarserver.org//changeset/12809
Author:   wsanchez at apple.com
Date:     2014-03-04 20:40:35 -0800 (Tue, 04 Mar 2014)
Log Message:
-----------
Use JobItem.all() instead of JobItem.histogram() so we can get at more data.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/webadmin/work.py

Modified: CalendarServer/trunk/calendarserver/webadmin/work.py
===================================================================
--- CalendarServer/trunk/calendarserver/webadmin/work.py	2014-03-05 04:39:53 UTC (rev 12808)
+++ CalendarServer/trunk/calendarserver/webadmin/work.py	2014-03-05 04:40:35 UTC (rev 12809)
@@ -89,7 +89,7 @@
     Resource that vends work queue information via HTML5 EventSource events.
     """
 
-    def __init__(self, store, pollInterval=1):
+    def __init__(self, store, pollInterval=1000):
         EventSourceResource.__init__(self, EventDecoder, bufferSize=1)
 
         self._store = store
@@ -106,22 +106,40 @@
     def poll(self):
         txn = self._store.newTransaction()
 
-        jobData = yield JobItem.histogram(txn)
+        # Look up all of the jobs
 
+        itemsByTypeName = {}
+
+        for item in (yield JobItem.all(txn)):
+            itemsByTypeName.setdefault(item.workType, []).append(item)
+
+        totalsByTypeName = dict(
+            (workType, len(items))
+            for (workType, items) in itemsByTypeName.iteritems()
+        )
+
+        for workType in JobItem.workTypes():
+            # If this workType isn't in the totals, there are zero of them.
+            totalsByTypeName.setdefault(workType.table.model.name, "0")
+
+        # Send data
+
         self.addEvents((
             dict(
                 eventClass=u"work-total",
                 eventID=time(),
-                eventText=asJSON(jobData),
-                eventRetry=(self._pollInterval * 1000),
+                eventText=asJSON(totalsByTypeName),
+                eventRetry=(self._pollInterval),
             ),
         ))
 
+        # Schedule the next poll
+
         if not hasattr(self, "_clock"):
             from twisted.internet import reactor
             self._clock = reactor
 
-        self._clock.callLater(self._pollInterval, self.poll)
+        self._clock.callLater(self._pollInterval / 1000, self.poll)
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140304/4e48fef8/attachment-0001.html>


More information about the calendarserver-changes mailing list