[Zope-CVS] CVS: Products/QueueCatalog - QueueCatalog.py:1.10

Shane Hathaway shane@zope.com
Tue, 29 Oct 2002 17:44:08 -0500


Update of /cvs-repository/Products/QueueCatalog
In directory cvs.zope.org:/tmp/cvs-serv413

Modified Files:
	QueueCatalog.py 
Log Message:
Added a max parameter to the process() method, useful for processing a limited number of events at once.  Also, the process() method now returns the number of events processed.  If you use the max parameter, call process() repeatedly until it returns 0.

=== Products/QueueCatalog/QueueCatalog.py 1.9 => 1.10 ===
--- Products/QueueCatalog/QueueCatalog.py:1.9	Tue Oct 15 10:55:14 2002
+++ Products/QueueCatalog/QueueCatalog.py	Tue Oct 29 17:44:08 2002
@@ -272,8 +272,12 @@
             self.process()
 
 
-    def process(self):
-        "Process pending events"
+    def process(self, max=None):
+        """Process pending events
+
+        Returns the number of events processed.
+        """
+        count = 0
         catalog = self.getZCatalog()
         for queue in filter(None, self._queues):
             events = queue.process()
@@ -288,6 +292,13 @@
                     # Note that the uid may be relative to the catalog.
                     obj = catalog.unrestrictedTraverse(uid)
                     catalog.catalog_object(obj, uid)
+                count = count + 1
+            if max and count >= max:
+                # On surpassing the maximum, return immediately
+                # so the caller can commit the transaction,
+                # sleep for a while, or do something else.
+                break
+        return count
 
     #
     # CMF catalog tool methods.