[Checkins] SVN: Sandbox/gotcha/five.taskqueue/src/five/taskqueue/ simple processor tests pass
Godefroid Chapelle
gotcha at bubblenet.be
Wed Apr 14 04:38:23 EDT 2010
Log message for revision 110833:
simple processor tests pass
Changed:
U Sandbox/gotcha/five.taskqueue/src/five/taskqueue/processor.py
U Sandbox/gotcha/five.taskqueue/src/five/taskqueue/service.py
U Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/processor.txt
U Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/test_doctests.py
-=-
Modified: Sandbox/gotcha/five.taskqueue/src/five/taskqueue/processor.py
===================================================================
--- Sandbox/gotcha/five.taskqueue/src/five/taskqueue/processor.py 2010-04-13 21:51:22 UTC (rev 110832)
+++ Sandbox/gotcha/five.taskqueue/src/five/taskqueue/processor.py 2010-04-14 08:38:22 UTC (rev 110833)
@@ -8,19 +8,26 @@
from z3c.taskqueue.processor import BaseSimpleProcessor
from z3c.taskqueue.processor import ERROR_MARKER
-log = logging.getLogger('five.taskqueue')
+log = logging.getLogger('z3c.taskqueue')
+class Response(HTTPResponse):
+ """override setBody to avoid that method result gets turned to a string."""
+
+ def setBody(self, body):
+ self.body = body
+
+
class SimpleProcessor(BaseSimpleProcessor):
""" SimpleProcessor for Zope2 """
def call(self, method, args=(), errorValue=ERROR_MARKER):
path = self.servicePath[:] + [method]
- response = HTTPResponse()
+ response = Response()
env = {'SERVER_NAME': 'dummy',
'SERVER_PORT': '8080',
'PATH_INFO': '/' + '/'.join(path)}
- log.info(env['PATH_INFO'])
+ log.info('Call "%s"' % env['PATH_INFO'])
request = HTTPRequest(None, env, response)
conn = self.db.open()
root = conn.root()
@@ -40,6 +47,3 @@
time.sleep(1)
else:
return request.response.body
-
- def processNext(self, jobid=None):
- return self.call('processNext', args=(None, jobid)) == "True"
Modified: Sandbox/gotcha/five.taskqueue/src/five/taskqueue/service.py
===================================================================
--- Sandbox/gotcha/five.taskqueue/src/five/taskqueue/service.py 2010-04-13 21:51:22 UTC (rev 110832)
+++ Sandbox/gotcha/five.taskqueue/src/five/taskqueue/service.py 2010-04-14 08:38:22 UTC (rev 110833)
@@ -5,11 +5,15 @@
from z3c.taskqueue.baseservice import BaseTaskService
+from five.taskqueue import processor
+
class TaskService(BaseTaskService, SimpleItem):
containerClass = IOBTree
maxint = sys.maxint
+ processorFactory = processor.SimpleProcessor
+
def getServicePath(self):
path = [part for part in self.getPhysicalPath() if part]
return path
Modified: Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/processor.txt
===================================================================
--- Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/processor.txt 2010-04-13 21:51:22 UTC (rev 110832)
+++ Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/processor.txt 2010-04-14 08:38:22 UTC (rev 110833)
@@ -15,10 +15,13 @@
>>> from five.taskqueue import service
>>> tasks = service.TaskService()
+ >>> tasks.id = 'tasks'
>>> root._setOb('tasks', tasks)
>>> tasks.__parent__ = root
>>> tasks.__name__ = 'tasks'
+ >>> tasks.getServicePath()
+ ['tasks']
2. Register the service as a utility:
@@ -65,27 +68,26 @@
the task service. All other arguments are optional:
>>> proc = processor.SimpleProcessor(
- ... tasks._p_jar.db(), ['tasks'], waitTime=0.0)
+ ... tasks._p_jar.db(), tasks.getServicePath(), waitTime=0.0)
-Let's now process the first job. We clear the log and we also have to end any
-existing interactions in order to process the job in this thread:
+Let's now process the first job. We clear the log.
>>> log_info.clear()
- >>> from zope.security import management
- >>> management.endInteraction()
>>> proc.processNext()
- 'True'
+ True
>>> print log_info
z3c.taskqueue INFO
+ Call "/tasks/processNext"
+ z3c.taskqueue INFO
Job: 1
Let's now use the processor from within the task service. Since the processor
constructors also accept additional arguments, they are specified as well:
>>> tasks.processorFactory
- <class 'z3c.taskqueue.processor.SimpleProcessor'>
+ <class 'five.taskqueue.processor.SimpleProcessor'>
>>> tasks.processorArguments
{'waitTime': 0.0}
@@ -106,16 +108,26 @@
>>> print log_info
z3c.taskqueue INFO
+ Call "/tasks/processNext"
+ z3c.taskqueue INFO
Job: 1
z3c.taskqueue INFO
starting service remotetasks.tasks.tasks
z3c.taskqueue INFO
+ Call "/tasks/processNext"
+ z3c.taskqueue INFO
Job: 2
z3c.taskqueue INFO
+ Call "/tasks/processNext"
+ z3c.taskqueue INFO
Job: 3
z3c.taskqueue INFO
+ Call "/tasks/processNext"
+ z3c.taskqueue INFO
Job: 4
z3c.taskqueue INFO
+ Call "/tasks/processNext"
+ z3c.taskqueue INFO
stopping service remotetasks.tasks.tasks
Transactions in jobs
@@ -170,7 +182,7 @@
method by itself. So we instantiate the processor:
>>> proc = processor.MultiProcessor(
- ... tasks._p_jar.db(), ['tasks'], waitTime=0)
+ ... tasks._p_jar.db(), tasks.getServicePath(), waitTime=0)
The maximum amount of threads can be set as well:
Modified: Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/test_doctests.py
===================================================================
--- Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/test_doctests.py 2010-04-13 21:51:22 UTC (rev 110832)
+++ Sandbox/gotcha/five.taskqueue/src/five/taskqueue/tests/test_doctests.py 2010-04-14 08:38:22 UTC (rev 110833)
@@ -19,7 +19,6 @@
from Testing import ZopeTestCase
from zope.testing.doctest import INTERPRET_FOOTNOTES
-from zope.testing.doctestunit import DocFileSuite
from zope.testing.loggingsupport import InstalledHandler
import doctest
import random
@@ -75,7 +74,8 @@
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestIdGenerator),
- DocFileSuite('processor.txt', package='five.taskqueue.tests',
+ ZopeTestCase.ZopeDocFileSuite('processor.txt',
+ package='five.taskqueue.tests',
setUp=setUp,
tearDown=tearDown,
optionflags=doctest.NORMALIZE_WHITESPACE
More information about the checkins
mailing list