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