[Checkins] SVN: lovely.remotetask/trunk/ guard against aborting the transaction inside the job, so it does not

Wolfgang Schnerring wosc at wosc.de
Fri Jul 31 08:47:51 EDT 2009


Log message for revision 102408:
  guard against aborting the transaction inside the job, so it does not
  lead to an infinite loop (because SimpleProcessor pulls the job inside the
  transaction, so if it is aborted, the job remains on the queue)
  

Changed:
  U   lovely.remotetask/trunk/CHANGES.txt
  U   lovely.remotetask/trunk/src/lovely/remotetask/processor.txt
  U   lovely.remotetask/trunk/src/lovely/remotetask/service.py

-=-
Modified: lovely.remotetask/trunk/CHANGES.txt
===================================================================
--- lovely.remotetask/trunk/CHANGES.txt	2009-07-31 12:47:39 UTC (rev 102407)
+++ lovely.remotetask/trunk/CHANGES.txt	2009-07-31 12:47:51 UTC (rev 102408)
@@ -5,6 +5,9 @@
 unreleased (0.5):
 -----------------
 
+- Fixed a bug with SimpleProcessor: if the job aborted the transaction, it would
+  never be removed from the queue, but re-tried over and over again.
+
 2009/05/20 (0.4):
 -----------------
 

Modified: lovely.remotetask/trunk/src/lovely/remotetask/processor.txt
===================================================================
--- lovely.remotetask/trunk/src/lovely/remotetask/processor.txt	2009-07-31 12:47:39 UTC (rev 102407)
+++ lovely.remotetask/trunk/src/lovely/remotetask/processor.txt	2009-07-31 12:47:51 UTC (rev 102408)
@@ -120,7 +120,40 @@
   lovely.remotetask INFO
     Job: 4
 
+Transactions in jobs
+--------------------
 
+With the SimpleProcessor, jobs _should_ not change the transaction status, since
+both the administration of the jobs by the TaskService and the job itself run in
+the same transaction, so aborting it from inside the job could wreak havoc with
+the administrative part.
+
+This is a regression test that aborting the transaction inside the job does not
+lead to an infinite loop (because SimpleProcessor pulls the job inside the
+transaction, so if it is aborted, the job remains on the queue):
+
+  >>> counter = 0
+  >>> def count(arg):
+  ...     global counter
+  ...     counter += 1
+  ...     transaction.abort()
+  >>> countTask = remotetask.task.SimpleTask(count)
+  >>> zope.component.provideUtility(countTask, name='count')
+
+  >>> jobid = tasks.add(u'count', ())
+  >>> transaction.commit()
+
+  >>> tasks.startProcessing()
+  >>> transaction.commit()
+  >>> time.sleep(0.5)
+  >>> tasks.stopProcessing()
+  >>> transaction.commit()
+  >>> time.sleep(0.5)
+  >>> transaction.abort() # prevent spurious conflict errors
+  >>> counter
+  1
+
+
 The Multi-thread Processor
 --------------------------
 
@@ -164,7 +197,7 @@
 
   >>> jobid = proc.claimNextJob()
   >>> jobid
-  1392637179
+  1392637180
 
 We need to claim a job before executing it, so that the database marks the job
 as claimed and no new thread picks up the job. Once we claimed a particular

Modified: lovely.remotetask/trunk/src/lovely/remotetask/service.py
===================================================================
--- lovely.remotetask/trunk/src/lovely/remotetask/service.py	2009-07-31 12:47:39 UTC (rev 102407)
+++ lovely.remotetask/trunk/src/lovely/remotetask/service.py	2009-07-31 12:47:51 UTC (rev 102408)
@@ -238,6 +238,8 @@
             job = self.jobs[jobid]
         if job is None:
             return False
+        if job.status == interfaces.COMPLETED:
+            return True
         try:
             jobtask = component.getUtility(self.taskInterface, name=job.task)
         except ComponentLookupError, error:



More information about the Checkins mailing list