Skip to content
This repository has been archived by the owner on Feb 12, 2020. It is now read-only.

Commit

Permalink
Store DB reference as global variable (should be done on DatabaseOpen…
Browse files Browse the repository at this point in the history
…edWithRoot)

Use that reference instead of accessing _p_jar
  • Loading branch information
jfroche committed Oct 18, 2010
1 parent 19e9ac8 commit 0c9922a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/z3c/taskqueue/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GLOBALDB = None
7 changes: 6 additions & 1 deletion src/z3c/taskqueue/baseservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from z3c.taskqueue import interfaces, job, task
from z3c.taskqueue import processor
import z3c.taskqueue

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

Expand Down Expand Up @@ -307,8 +308,12 @@ def startProcessing(self):
servicePath = self.getServicePath()
log.info('starting service %s' % ".".join(servicePath))
# Start the thread running the processor inside.
#
db = z3c.taskqueue.GLOBALDB
if db is None:
raise ValueError('z3c.taskqueue.GLOBALDB is not initialized; should be done with IDatabaseOpenedWithRootEvent')
processor = self.processorFactory(
self._p_jar.db(), servicePath, **self.processorArguments)
db, servicePath, **self.processorArguments)
threadName = self._threadName()
thread = threading.Thread(target=processor, name=threadName)
thread.setDaemon(True)
Expand Down
3 changes: 2 additions & 1 deletion src/z3c/taskqueue/processor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ API. Let's create the necessary components to test the processor:
>>> conn = db.open()
>>> conn.root()[ZopePublication.root_name] = root
>>> transaction.commit()

>>> from z3c.taskqueue.startup import storeDBReference
>>> storeDBReference(db)

The Simple Processor
--------------------
Expand Down
11 changes: 10 additions & 1 deletion src/z3c/taskqueue/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import logging
import zope.interface
import zope.location
import z3c.taskqueue


log = logging.getLogger('z3c.taskqueue')
Expand All @@ -31,7 +32,7 @@ def databaseOpened(event, productName='z3c.taskqueue'):
"""Start the queue processing services based on the
settings in zope.conf"""
log.info('handling event IDatabaseOpenedEvent')

storeDBReference(event)
root_folder = getRootFolder(event)

from zope.app.appsetup.product import getProductConfiguration
Expand Down Expand Up @@ -176,3 +177,11 @@ def getService(site, serviceName):
msg = 'service %s on site %s not found'
log.error(msg % (serviceName, siteName))
return None


def storeDBReference(db):
z3c.taskqueue.GLOBALDB = db


def storeDBReferenceOnDBOpened(event):
storeDBReference(event.database)

0 comments on commit 0c9922a

Please sign in to comment.