Commit 9c090c35 authored by Vincent Pelletier's avatar Vincent Pelletier

When SQL{Dict|Queue}_delMessage gets a lock error, retry. Do so infinitely,...

When SQL{Dict|Queue}_delMessage gets a lock error, retry. Do so infinitely, otherwise uid list would be lost and manual intervention would be required.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20306 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2ca17413
......@@ -26,6 +26,10 @@
#
##############################################################################
from _mysql_exceptions import OperationalError
from MySQLdb.constants import ER
from zLOG import LOG, INFO
class SQLBase:
"""
Define a set of common methods for SQL-based storage of activities.
......@@ -49,3 +53,20 @@ class SQLBase:
if priority is None:
priority = default
return priority
def _retryOnLockError(self, method, args=(), kw=None):
if kw is None:
kw = {}
while True:
try:
result = method(*args, **kw)
except OperationalError, value:
if isinstance(value, OperationalError) and \
value[0] in (ER.LOCK_WAIT_TIMEOUT, ER.LOCK_DEADLOCK):
LOG('SQLBase', INFO, 'Got a lock error, retrying...')
else:
raise
else:
break
return result
......@@ -378,7 +378,7 @@ class SQLDict(RAMDict, SQLBase):
delay_uid_list.append(uid)
if len(deletable_uid_list):
try:
activity_tool.SQLDict_delMessage(uid=deletable_uid_list)
self._retryOnLockError(activity_tool.SQLDict_delMessage, kw={'uid': deletable_uid_list})
except:
LOG('SQLDict', ERROR, 'Failed to delete messages %r' % (deletable_uid_list, ), error=sys.exc_info())
else:
......
......@@ -226,7 +226,7 @@ class SQLQueue(RAMQueue, SQLBase):
LOG('SQLQueue', TRACE, 'Freed message %r' % (uid, ))
if len(deletable_uid_list):
try:
activity_tool.SQLQueue_delMessage(uid=deletable_uid_list)
self._retryOnLockError(activity_tool.SQLQueue_delMessage, kw={'uid': deletable_uid_list})
except:
LOG('SQLQueue', ERROR, 'Failed to delete messages %r' % (deletable_uid_list, ), error=sys.exc_info())
else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment