From b44816f6ad771c9ca357410296e0e934738e6fff Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 5 Feb 2008 22:39:58 +0000
Subject: [PATCH] Lower log priority from PANIC to ERROR for message status
 handling definitive errors (reserve PANIC priority to permanent data
 inconsistency). When a PANIC level error happens, re-raise after logging
 instead of simply returning.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19090 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFActivity/Activity/SQLDict.py  | 18 +++++++++---------
 product/CMFActivity/Activity/SQLQueue.py | 18 +++++++++---------
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/product/CMFActivity/Activity/SQLDict.py b/product/CMFActivity/Activity/SQLDict.py
index c595c239b8..0d4e12f0eb 100644
--- a/product/CMFActivity/Activity/SQLDict.py
+++ b/product/CMFActivity/Activity/SQLDict.py
@@ -294,7 +294,7 @@ class SQLDict(RAMDict, SQLBase):
         try:
           makeMessageListAvailable(to_free_uid_list)
         except:
-          LOG('SQLDict', PANIC, 'Failed to free messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
+          LOG('SQLDict', ERROR, 'Failed to free messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
         else:
           if len(to_free_uid_list):
             LOG('SQLDict', TRACE, 'Freed messages %r' % (to_free_uid_list, ))
@@ -350,7 +350,7 @@ class SQLDict(RAMDict, SQLBase):
       try:
         activity_tool.SQLDict_delMessage(uid=deletable_uid_list)
       except:
-        LOG('SQLDict', PANIC, 'Failed to delete messages %r' % (deletable_uid_list, ), error=sys.exc_info())
+        LOG('SQLDict', ERROR, 'Failed to delete messages %r' % (deletable_uid_list, ), error=sys.exc_info())
       else:
         LOG('SQLDict', TRACE, 'Deleted messages %r' % (deletable_uid_list, ))
     if len(delay_uid_list):
@@ -358,19 +358,19 @@ class SQLDict(RAMDict, SQLBase):
         # If this is a conflict error, do not lower the priority but only delay.
         activity_tool.SQLDict_setPriority(uid=delay_uid_list, delay=VALIDATION_ERROR_DELAY)
       except:
-        LOG('SQLDict', PANIC, 'Failed to delay %r' % (delay_uid_list, ), error=sys.exc_info())
+        LOG('SQLDict', ERROR, 'Failed to delay %r' % (delay_uid_list, ), error=sys.exc_info())
       make_available_uid_list += delay_uid_list
     if len(final_error_uid_list):
       try:
         activity_tool.SQLDict_assignMessage(uid=final_error_uid_list,
                                             processing_node=INVOKE_ERROR_STATE)
       except:
-        LOG('SQLDict', PANIC, 'Failed to set message to error state for %r' % (final_error_uid_list, ), error=sys.exc_info())
+        LOG('SQLDict', ERROR, 'Failed to set message to error state for %r' % (final_error_uid_list, ), error=sys.exc_info())
     if len(make_available_uid_list):
       try:
         makeMessageListAvailable(make_available_uid_list)
       except:
-        LOG('SQLDict', PANIC, 'Failed to unreserve %r' % (make_available_uid_list, ), error=sys.exc_info())
+        LOG('SQLDict', ERROR, 'Failed to unreserve %r' % (make_available_uid_list, ), error=sys.exc_info())
       else:
         LOG('SQLDict', TRACE, 'Freed messages %r' % (make_available_uid_list, ))
     try:
@@ -421,12 +421,12 @@ class SQLDict(RAMDict, SQLBase):
           # Unfortunately, database adapters may raise an exception against abort.
           LOG('SQLDict', PANIC,
               'abort failed, thus some objects may be modified accidentally')
-          return True # Stop processing messages for this tic call for this queue.
+          raise
         to_free_uid_list = [x[0] for x in message_uid_priority_list]
         try:
           makeMessageListAvailable(to_free_uid_list)
         except:
-          LOG('SQLDict', PANIC, 'Failed to free messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
+          LOG('SQLDict', ERROR, 'Failed to free messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
         else:
           LOG('SQLDict', TRACE, 'Freed messages %r' % (to_free_uid_list))
       # Abort if something failed.
@@ -445,12 +445,12 @@ class SQLDict(RAMDict, SQLBase):
             abortTransactionSynchronously()
           except:
             LOG('SQLDict', PANIC, 'Failed to abort executed messages which also failed to commit. Some objects may be modified accidentally.')
-            return True # Stop processing messages for this tic call for this queue.
+            raise
         failed_message_uid_list = [x[0] for x in message_uid_priority_list]
         try:
           makeMessageListAvailable(failed_message_uid_list)
         except:
-          LOG('SQLDict', PANIC, 'Failed to free remaining messages: %r' % (failed_message_uid_list, ), error=sys.exc_info())
+          LOG('SQLDict', ERROR, 'Failed to free remaining messages: %r' % (failed_message_uid_list, ), error=sys.exc_info())
         else:
           LOG('SQLDict', TRACE, 'Freed messages %r' % (failed_message_uid_list, ))
       self.finalizeMessageExecution(activity_tool, message_uid_priority_list)
diff --git a/product/CMFActivity/Activity/SQLQueue.py b/product/CMFActivity/Activity/SQLQueue.py
index 60c20dd958..5475f3aa49 100644
--- a/product/CMFActivity/Activity/SQLQueue.py
+++ b/product/CMFActivity/Activity/SQLQueue.py
@@ -176,7 +176,7 @@ class SQLQueue(RAMQueue, SQLBase):
         try:
           makeMessageListAvailable(to_free_uid_list)
         except:
-          LOG('SQLQueue', PANIC, 'Failed to free messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
+          LOG('SQLQueue', ERROR, 'Failed to free messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
         else:
           if len(to_free_uid_list):
             LOG('SQLQueue', TRACE, 'Freed messages %r' % (to_free_uid_list, ))
@@ -216,14 +216,14 @@ class SQLQueue(RAMQueue, SQLBase):
           try:
             makeMessageListAvailable(delay_uid_list)
           except:
-            LOG('SQLQueue', PANIC, 'Failed to unreserve %r' % (uid, ), error=sys.exc_info())
+            LOG('SQLQueue', ERROR, 'Failed to unreserve %r' % (uid, ), error=sys.exc_info())
           else:
             LOG('SQLQueue', TRACE, 'Freed message %r' % (uid, ))
     if len(deletable_uid_list):
       try:
         activity_tool.SQLQueue_delMessage(uid=deletable_uid_list)
       except:
-        LOG('SQLQueue', PANIC, 'Failed to delete messages %r' % (deletable_uid_list, ), error=sys.exc_info())
+        LOG('SQLQueue', ERROR, 'Failed to delete messages %r' % (deletable_uid_list, ), error=sys.exc_info())
       else:
         LOG('SQLQueue', TRACE, 'Deleted messages %r' % (deletable_uid_list, ))
     if len(delay_uid_list):
@@ -231,11 +231,11 @@ class SQLQueue(RAMQueue, SQLBase):
         # If this is a conflict error, do not lower the priority but only delay.
         activity_tool.SQLQueue_setPriority(uid=delay_uid_list, delay=VALIDATION_ERROR_DELAY)
       except:
-        LOG('SQLQueue', PANIC, 'Failed to delay %r' % (delay_uid_list, ), error=sys.exc_info())
+        LOG('SQLQueue', ERROR, 'Failed to delay %r' % (delay_uid_list, ), error=sys.exc_info())
       try:
         makeMessageListAvailable(delay_uid_list)
       except:
-        LOG('SQLQueue', PANIC, 'Failed to unreserve %r' % (delay_uid_list, ), error=sys.exc_info())
+        LOG('SQLQueue', ERROR, 'Failed to unreserve %r' % (delay_uid_list, ), error=sys.exc_info())
       else:
         LOG('SQLQueue', TRACE, 'Freed messages %r' % (delay_uid_list, ))
     if len(final_error_uid_list):
@@ -243,7 +243,7 @@ class SQLQueue(RAMQueue, SQLBase):
         activity_tool.SQLQueue_assignMessage(uid=final_error_uid_list,
                                              processing_node=INVOKE_ERROR_STATE)
       except:
-        LOG('SQLQueue', PANIC, 'Failed to set message to error state for %r' % (final_error_uid_list, ), error=sys.exc_info())
+        LOG('SQLQueue', ERROR, 'Failed to set message to error state for %r' % (final_error_uid_list, ), error=sys.exc_info())
     try:
       for m in notify_user_list:
         m.notifyUser(activity_tool)
@@ -293,7 +293,7 @@ class SQLQueue(RAMQueue, SQLBase):
           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.
+            raise
           # 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
@@ -301,7 +301,7 @@ class SQLQueue(RAMQueue, SQLBase):
           try:
             makeMessageListAvailable([value[0]])
           except:
-            LOG('SQLQueue', PANIC, 'Failed to free message: %r' % (value, ), error=sys.exc_info())
+            LOG('SQLQueue', ERROR, 'Failed to free message: %r' % (value, ), error=sys.exc_info())
           else:
             LOG('SQLQueue', TRACE, 'Freed message %r' % (value, ))
         if time() > processing_stop_time:
@@ -314,7 +314,7 @@ class SQLQueue(RAMQueue, SQLBase):
         try:
           makeMessageListAvailable(to_free_uid_list)
         except:
-          LOG('SQLQueue', PANIC, 'Failed to free remaining messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
+          LOG('SQLQueue', ERROR, 'Failed to free remaining messages: %r' % (to_free_uid_list, ), error=sys.exc_info())
         else:
           LOG('SQLQueue', TRACE, 'Freed messages %r' % (to_free_uid_list, ))
       self.finalizeMessageExecution(activity_tool, processed_message_uid_list)
-- 
2.30.9