[Checkins] SVN: Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/ Store DB reference as global variable (should be done on DatabaseOpenedWithRoot)

Jean-Francois Roche jfroche at jfroche.be
Mon Oct 18 10:10:01 EDT 2010


Log message for revision 117710:
  Store DB reference as global variable (should be done on DatabaseOpenedWithRoot)
  Use that reference instead of accessing _p_jar
  
  

Changed:
  U   Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/__init__.py
  U   Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/baseservice.py
  U   Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/processor.txt
  U   Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/startup.py

-=-
Modified: Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/__init__.py
===================================================================
--- Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/__init__.py	2010-10-18 14:08:37 UTC (rev 117709)
+++ Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/__init__.py	2010-10-18 14:10:00 UTC (rev 117710)
@@ -0,0 +1 @@
+GLOBALDB = None

Modified: Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/baseservice.py
===================================================================
--- Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/baseservice.py	2010-10-18 14:08:37 UTC (rev 117709)
+++ Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/baseservice.py	2010-10-18 14:10:00 UTC (rev 117710)
@@ -30,6 +30,7 @@
 
 from z3c.taskqueue import interfaces, job, task
 from z3c.taskqueue import processor
+import z3c.taskqueue
 
 log = logging.getLogger('z3c.taskqueue')
 
@@ -307,8 +308,12 @@
         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)

Modified: Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/processor.txt
===================================================================
--- Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/processor.txt	2010-10-18 14:08:37 UTC (rev 117709)
+++ Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/processor.txt	2010-10-18 14:10:00 UTC (rev 117710)
@@ -49,8 +49,9 @@
   >>> conn = db.open()
   >>> conn.root()[ZopePublication.root_name] = root
   >>> transaction.commit()
+  >>> from z3c.taskqueue.startup import storeDBReference
+  >>> storeDBReference(db)
 
-
 The Simple Processor
 --------------------
 

Modified: Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/startup.py
===================================================================
--- Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/startup.py	2010-10-18 14:08:37 UTC (rev 117709)
+++ Sandbox/gotcha/z3c.taskqueue/trunk/src/z3c/taskqueue/startup.py	2010-10-18 14:10:00 UTC (rev 117710)
@@ -22,6 +22,7 @@
 import logging
 import zope.interface
 import zope.location
+import z3c.taskqueue
 
 
 log = logging.getLogger('z3c.taskqueue')
@@ -31,7 +32,7 @@
     """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
@@ -176,3 +177,11 @@
         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)



More information about the checkins mailing list