[Checkins] SVN: Sandbox/gotcha/z3c.taskqueue/src/z3c/taskqueue/processor.py Refactor processor for simpler reuse by five.taskqueue

Godefroid Chapelle gotcha at bubblenet.be
Wed Apr 14 05:46:20 EDT 2010


Log message for revision 110839:
  Refactor processor for simpler reuse by five.taskqueue
  
  Remove leftover zope2 code
  

Changed:
  U   Sandbox/gotcha/z3c.taskqueue/src/z3c/taskqueue/processor.py

-=-
Modified: Sandbox/gotcha/z3c.taskqueue/src/z3c/taskqueue/processor.py
===================================================================
--- Sandbox/gotcha/z3c.taskqueue/src/z3c/taskqueue/processor.py	2010-04-14 09:44:49 UTC (rev 110838)
+++ Sandbox/gotcha/z3c.taskqueue/src/z3c/taskqueue/processor.py	2010-04-14 09:46:19 UTC (rev 110839)
@@ -23,7 +23,6 @@
 import zope.interface
 import zope.publisher.base
 import zope.publisher.publish
-import types
 from zope.app.publication.zopepublication import ZopePublication
 from zope.security import management
 from zope.security.proxy import removeSecurityProxy
@@ -84,7 +83,8 @@
         raise NotImplemented
 
     def processNext(self, jobid=None):
-        return self.call('processNext', args=(None, jobid))
+        result = self.call('processNext', args=(None, jobid))
+        return result
 
     def __call__(self):
         while self.running:
@@ -95,7 +95,7 @@
                 time.sleep(self.waitTime)
 
 
-class SimpleProcessor(BaseSimpleProcessor):
+class Z3PublisherMixin(object):
 
     def call(self, method, args=(), errorValue=ERROR_MARKER):
         # Create the path to the method.
@@ -117,7 +117,11 @@
             return errorValue is ERROR_MARKER and error or errorValue
 
 
-class BaseMultiProcessor(SimpleProcessor):
+class SimpleProcessor(Z3PublisherMixin, BaseSimpleProcessor):
+    """ Z3 compatible processor"""
+
+
+class BaseMultiProcessor(BaseSimpleProcessor):
     """Multi-threaded Job Processor
 
     This processor can work on multiple jobs at the same time.
@@ -164,35 +168,5 @@
                 time.sleep(THREAD_STARTUP_WAIT)
 
 
-class MultiProcessor(BaseMultiProcessor):
-    """Multi-threaded Job Processor
-
-    This processor can work on multiple jobs at the same time.
-
-    WARNING: This still does not work correctly in Zope2
-    """
-    zope.interface.implements(interfaces.IProcessor)
-
-    def __init__(self, *args, **kwargs):
-        self.maxThreads = kwargs.pop('maxThreads', 5)
-        super(MultiProcessor, self).__init__(*args, **kwargs)
-        self.threads = []
-
-    def hasJobsWaiting(self):
-        value = self.call('hasJobsWaiting', errorValue=False)
-        if isinstance(value, types.StringType):
-            if value == 'True':
-                return True
-            else:
-                return False
-        return value
-
-    def claimNextJob(self):
-        value = self.call('claimNextJob', errorValue=None)
-        try:
-            value = int(value)
-        except TypeError:
-            log.debug(value)
-        except ValueError:
-            pass
-        return value
+class MultiProcessor(Z3PublisherMixin, BaseMultiProcessor):
+    """ Z3 compatible processor"""



More information about the checkins mailing list