Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
remove reference to _p_jar
Browse files Browse the repository at this point in the history
fix test after change to use z2 processor
  • Loading branch information
jfroche committed Oct 18, 2010
1 parent f484ecd commit bb82487
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
22 changes: 14 additions & 8 deletions src/five/taskqueue/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,35 @@

from z3c.taskqueue.startup import getRootFolder
from z3c.taskqueue.startup import getStartSpecifications
from z3c.taskqueue.startup import startOneService
from z3c.taskqueue.startup import startOneService, storeDBReference

log = logging.getLogger('five.taskqueue')


def databaseOpened(event):
"""Start the queue processing services based on the
settings in zope.conf"""
log.info('handling event IDatabaseOpenedEvent')

root_folder = getRootFolder(event)

def startServices(root_folder):
configuration = getTaskqueueConfiguration()
startSpecifications = getStartSpecifications(configuration)

for siteName, serviceName in startSpecifications:
log.debug('Starting service %s from site %s' % (serviceName, siteName))
site = getSite(siteName, root_folder)
if site is None:
continue
started = startOneService(site, serviceName)
if not started:
msg = 'service %s from site %s was not started.'
log.warn(msg % (serviceName, siteName))
else:
log.debug('Service %s from site %s started.' % (serviceName, siteName))


def databaseOpened(event):
"""Start the queue processing services based on the
settings in zope.conf"""
log.info('handling event IDatabaseOpenedEvent')
storeDBReference(event)
root_folder = getRootFolder(event)
startServices(root_folder)


def getSite(siteName, root_folder):
Expand Down
22 changes: 14 additions & 8 deletions src/five/taskqueue/tests/processor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ API. Let's create the necessary components to test the processor:

>>> import zope.component
>>> zope.component.provideUtility(sleepTask, name='sleep')
>>> import Zope2
>>> from z3c.taskqueue.startup import storeDBReference
>>> storeDBReference(Zope2.DB)


The Simple Processor
Expand All @@ -67,8 +70,10 @@ Let's start by executing a job directly. The first argument to the simple
processor constructor is the database and the second the traversal stack to
the task service. All other arguments are optional:

>>> import z3c.taskqueue
>>> db = z3c.taskqueue.GLOBALDB
>>> proc = processor.SimpleProcessor(
... tasks._p_jar.db(), tasks.getServicePath(), waitTime=0.0)
... db, tasks.getServicePath(), waitTime=0.0)

Let's now process the first job. We clear the log.

Expand Down Expand Up @@ -108,15 +113,15 @@ were all completed in the order they were defined.
z3c.taskqueue INFO
Job: 1
z3c.taskqueue INFO
starting service remotetasks.tasks.tasks
starting service tasks
z3c.taskqueue INFO
Job: 2
z3c.taskqueue INFO
Job: 3
z3c.taskqueue INFO
Job: 4
z3c.taskqueue INFO
stopping service remotetasks.tasks.tasks
stopping service tasks

Transactions in jobs
--------------------
Expand Down Expand Up @@ -176,8 +181,9 @@ Let's add a few new tasks to execute:
Before testing the processor in the task service, let's have a look at every
method by itself. So we instantiate the processor:

>>> db = z3c.taskqueue.GLOBALDB
>>> proc = processor.MultiProcessor(
... tasks._p_jar.db(), tasks.getServicePath(), waitTime=0)
... db, tasks.getServicePath(), waitTime=0)

The maximum amount of threads can be set as well:

Expand Down Expand Up @@ -242,15 +248,15 @@ all need different time to execute:

>>> print log_info
z3c.taskqueue INFO
starting service remotetasks.tasks.tasks
starting service tasks
z3c.taskqueue INFO
Job: 3
z3c.taskqueue INFO
Job: 4
z3c.taskqueue INFO
Job: 2
z3c.taskqueue INFO
stopping service remotetasks.tasks.tasks
stopping service tasks


Let's now set the thread limit to two and construct a new set of tasks that
Expand Down Expand Up @@ -280,7 +286,7 @@ the jobs and see the result:

>>> print log_info
z3c.taskqueue INFO
starting service remotetasks.tasks.tasks
starting service tasks
z3c.taskqueue INFO
Job: 1
z3c.taskqueue INFO
Expand All @@ -290,7 +296,7 @@ the jobs and see the result:
z3c.taskqueue INFO
Job: 4
z3c.taskqueue INFO
stopping service remotetasks.tasks.tasks
stopping service tasks

>>> print conflict_logger

Expand Down

0 comments on commit bb82487

Please sign in to comment.