Commit 28d6f1ad authored by Julien Muchembled's avatar Julien Muchembled

Improve notification in case of failed activity

* Change subject from "Failed Processing Activity" to
  "Activity failed: <path>/<method>"
* The subject starts with "Pending activity already failed <failures> times:"
  if CMFActivity is going to reexecute indefinitely.
* Drop the first line of the body. It was repeating the the subject.
* Add number of failures.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32880 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1ac567bf
......@@ -171,13 +171,13 @@ class SQLBase:
retry = m.line.retry
if max_retry is not None and retry >= max_retry:
# Always notify when we stop retrying.
notify_user_list.append(m)
notify_user_list.append((m, False))
final_error_uid_list.append(uid)
continue
# In case of infinite retry, notify the user
# when the default limit is reached.
if max_retry is None and retry == m.__class__.max_retry:
notify_user_list.append(m)
notify_user_list.append((m, True))
delay = m.delay
if delay is None:
# By default, make delay quadratic to the number of retries.
......@@ -235,8 +235,8 @@ class SQLBase:
else:
self._log(TRACE, 'Freed messages %r' % make_available_uid_list)
try:
for m in notify_user_list:
m.notifyUser(activity_tool)
for m, retry in notify_user_list:
m.notifyUser(activity_tool, retry)
except:
# Notification failures must not cause this method to raise.
self._log(WARNING,
......
......@@ -310,7 +310,7 @@ class Message(BaseMessage):
def getDependentMessageList(self, activity, activity_tool):
return activity.getDependentMessageList(activity_tool, self, **self.activity_kw)
def notifyUser(self, activity_tool, message="Failed Processing Activity"):
def notifyUser(self, activity_tool, retry=False):
"""Notify the user that the activity failed."""
portal = activity_tool.getPortalObject()
user_email = portal.getProperty('email_to_address',
......@@ -322,13 +322,18 @@ class Message(BaseMessage):
if self.call_traceback:
call_traceback = 'Created at:\n%s' % self.call_traceback
fail_count = self.line.retry + 1
if retry:
message = "Pending activity already failed %s times" % fail_count
else:
message = "Activity failed"
path = '/'.join(self.object_path)
mail_text = """From: %s <%s>
To: %s
Subject: %s
%s
Subject: %s: %s/%s
Node: %s
Failures: %s
User name: %r
Document: %s
Method: %s
......@@ -339,10 +344,10 @@ Named Parameters: %r
Exception: %s %s
%s
""" % (email_from_name, activity_tool.email_from_address,
user_email, message, message,
activity_tool.getCurrentNode(), self.user_name,
'/'.join(self.object_path), self.method_id, self.args, self.kw,
""" % (email_from_name, activity_tool.email_from_address, user_email,
message, path, self.method_id,
activity_tool.getCurrentNode(), fail_count,
self.user_name, path, self.method_id, self.args, self.kw,
call_traceback, self.exc_type, self.exc_value, self.traceback)
if isinstance(mail_text, unicode):
......
......@@ -1562,7 +1562,7 @@ class TestCMFActivity(ERP5TypeTestCase):
# Monkey patch Message not to send failure notification emails
from Products.CMFActivity.ActivityTool import Message
originalNotifyUser = Message.notifyUser
def notifyUserSilent(self, activity_tool, message=''):
def notifyUserSilent(self, *args, **kw):
pass
Message.notifyUser = notifyUserSilent
......@@ -1645,7 +1645,7 @@ class TestCMFActivity(ERP5TypeTestCase):
# Monkey patch Message not to send failure notification emails
from Products.CMFActivity.ActivityTool import Message
originalNotifyUser = Message.notifyUser
def notifyUserSilent(self, activity_tool, message=''):
def notifyUserSilent(self, *args, **kw):
pass
Message.notifyUser = notifyUserSilent
......@@ -2324,7 +2324,7 @@ class TestCMFActivity(ERP5TypeTestCase):
# monkeypatch method.
notification_done = []
from Products.CMFActivity.ActivityTool import Message
def fake_notifyUser(self, activity_tool):
def fake_notifyUser(self, *args, **kw):
notification_done.append(True)
original_notifyUser = Message.notifyUser
def failingMethod(self):
......
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