From 2c49f5053dfb535632e498c2048e38cd2ecbc52d Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 5 Feb 2008 18:13:52 +0000
Subject: [PATCH] Abort transaction before doing anything else: if it was
 transaction commit which raised, the transaction object will refuse
 subsequent "join" calls. Add some zope transation backward compatibility
 black magic and you get a TM instance which gets stalled in "registered"
 state while no transaction knows it.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19076 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFActivity/Activity/SQLQueue.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/product/CMFActivity/Activity/SQLQueue.py b/product/CMFActivity/Activity/SQLQueue.py
index ca94e1ba92..75e43bdc15 100644
--- a/product/CMFActivity/Activity/SQLQueue.py
+++ b/product/CMFActivity/Activity/SQLQueue.py
@@ -284,11 +284,17 @@ class SQLQueue(RAMQueue, SQLBase):
             # This message failed, revert.
             abortTransactionSynchronously()
         except:
+          LOG('SQLQueue', WARNING, 'Exception raised when invoking message (uid, path, method_id) %r' % ((value[0], value[1].object_path, value[1].method_id), ), error=sys.exc_info())
+          try:
+            abortTransactionSynchronously()
+          except:
+            # Unfortunately, database adapters may raise an exception against abort.
+            LOG('SQLQueue', PANIC, 'abort failed, thus some objects may be modified accidentally')
+            return True # Stop processing messages for this tic call for this queue.
           # We must make sure that the message is not set as executed.
           # It is possible that the message is executed but the commit
           # of the transaction fails
           value[1].is_executed = 0
-          LOG('SQLQueue', WARNING, 'Exception raised when invoking message (uid, path, method_id) %r' % ((value[0], value[1].object_path, value[1].method_id), ), error=sys.exc_info())
           try:
             # Rollback all changes made on activity connection.
             # We will commit to make messages available, and we cannot control
@@ -302,12 +308,6 @@ class SQLQueue(RAMQueue, SQLBase):
             LOG('SQLQueue', PANIC, 'Failed to free message: %r' % (value, ), error=sys.exc_info())
           else:
             LOG('SQLQueue', TRACE, 'Freed message %r' % (value, ))
-          try:
-            abortTransactionSynchronously()
-          except:
-            # Unfortunately, database adapters may raise an exception against abort.
-            LOG('SQLQueue', PANIC, 'abort failed, thus some objects may be modified accidentally')
-            return True # Stop processing messages for this tic call for this queue.
         if time() > processing_stop_time:
           LOG('SQLQueue', TRACE, 'Stop processing message batch because processing delay exceeded')
           break
-- 
2.30.9