summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2012-05-14 11:20:51 -0400
committerBarry Warsaw2012-05-14 11:20:51 -0400
commit3c8a07fc76176a8ea89ee6b73aef571d0b2c81ed (patch)
tree050093ca9114e40da200d7cebb2e1565bafd7d33 /src
parentfeb7316c554db4df76fd021468df2f1a69d894dd (diff)
parentcc449f1910f84894a2431920d9349bffe4cea7ab (diff)
downloadmailman-3c8a07fc76176a8ea89ee6b73aef571d0b2c81ed.tar.gz
mailman-3c8a07fc76176a8ea89ee6b73aef571d0b2c81ed.tar.zst
mailman-3c8a07fc76176a8ea89ee6b73aef571d0b2c81ed.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/core/runner.py10
-rw-r--r--src/mailman/core/tests/test_runner.py89
-rw-r--r--src/mailman/docs/NEWS.rst4
-rw-r--r--src/mailman/interfaces/runner.py13
4 files changed, 114 insertions, 2 deletions
diff --git a/src/mailman/core/runner.py b/src/mailman/core/runner.py
index 39382cea0..a79f19fbc 100644
--- a/src/mailman/core/runner.py
+++ b/src/mailman/core/runner.py
@@ -32,6 +32,7 @@ import traceback
from cStringIO import StringIO
from lazr.config import as_boolean, as_timedelta
from zope.component import getUtility
+from zope.event import notify
from zope.interface import implementer
from mailman.config import config
@@ -39,7 +40,7 @@ from mailman.core.i18n import _
from mailman.core.switchboard import Switchboard
from mailman.interfaces.languages import ILanguageManager
from mailman.interfaces.listmanager import IListManager
-from mailman.interfaces.runner import IRunner
+from mailman.interfaces.runner import IRunner, RunnerCrashEvent
from mailman.utilities.string import expand
@@ -216,7 +217,12 @@ class Runner:
language = mlist.preferred_language
with _.using(language.code):
msgdata['lang'] = language.code
- keepqueued = self._dispose(mlist, msg, msgdata)
+ try:
+ keepqueued = self._dispose(mlist, msg, msgdata)
+ except Exception as error:
+ # Trigger the Zope event and re-raise
+ notify(RunnerCrashEvent(self, mlist, msg, msgdata, error))
+ raise
if keepqueued:
self.switchboard.enqueue(msg, msgdata)
diff --git a/src/mailman/core/tests/test_runner.py b/src/mailman/core/tests/test_runner.py
new file mode 100644
index 000000000..ad2548adc
--- /dev/null
+++ b/src/mailman/core/tests/test_runner.py
@@ -0,0 +1,89 @@
+# Copyright (C) 2012 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test some Runner base class behavior."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestRunner',
+ ]
+
+
+import unittest
+
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.core.runner import Runner
+from mailman.interfaces.runner import RunnerCrashEvent
+from mailman.testing.helpers import (
+ configuration, event_subscribers, get_queue_messages,
+ make_testable_runner, specialized_message_from_string as mfs)
+from mailman.testing.layers import ConfigLayer
+
+
+
+class CrashingRunner(Runner):
+ def _dispose(self, mlist, msg, msgdata):
+ raise RuntimeError('borked')
+
+
+
+class TestRunner(unittest.TestCase):
+ """Test the Runner base class behavior."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ self._events = []
+
+ def _got_event(self, event):
+ self._events.append(event)
+
+ @configuration('runner.crashing',
+ **{'class': 'mailman.core.tests.CrashingRunner'})
+ def test_crash_event(self):
+ runner = make_testable_runner(CrashingRunner, 'in')
+ # When an exception occurs in Runner._process_one_file(), a zope.event
+ # gets triggered containing the exception object.
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Message-ID: <ant>
+
+""")
+ config.switchboards['in'].enqueue(msg, listname='test@example.com')
+ with event_subscribers(self._got_event):
+ runner.run()
+ # We should now have exactly one event, which will contain the
+ # exception, plus additional metadata containing the mailing list,
+ # message, and metadata.
+ self.assertEqual(len(self._events), 1)
+ event = self._events[0]
+ self.assertTrue(isinstance(event, RunnerCrashEvent))
+ self.assertEqual(event.mailing_list, self._mlist)
+ self.assertEqual(event.message['message-id'], '<ant>')
+ self.assertEqual(event.metadata['listname'], 'test@example.com')
+ self.assertTrue(isinstance(event.error, RuntimeError))
+ self.assertEqual(event.error.message, 'borked')
+ self.assertTrue(isinstance(event.runner, CrashingRunner))
+ # The message should also have ended up in the shunt queue.
+ shunted = get_queue_messages('shunt')
+ self.assertEqual(len(shunted), 1)
+ self.assertEqual(shunted[0].msg['message-id'], '<ant>')
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 9095f48c3..fb819ccc4 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -31,6 +31,10 @@ Architecture
or unverified. (LP: #975698)
* A `PasswordChangeEvent` is triggered when an `IUser`'s password changes.
(LP: #975700)
+ * When a queue runner gets an exception in its _dispose() method, a
+ `RunnerCrashEvent` is triggered, which contains references to the queue
+ runner, mailing list, message, metadata, and exception. Interested parties
+ can subscribe to that `zope.event` for notification.
Configuration
-------------
diff --git a/src/mailman/interfaces/runner.py b/src/mailman/interfaces/runner.py
index 4611fa3a7..9a3c9baa4 100644
--- a/src/mailman/interfaces/runner.py
+++ b/src/mailman/interfaces/runner.py
@@ -22,6 +22,7 @@ from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'IRunner',
+ 'RunnerCrashEvent',
]
@@ -29,6 +30,18 @@ from zope.interface import Interface, Attribute
+class RunnerCrashEvent:
+ """Triggered when a runner encounters an exception in _dispose()."""
+
+ def __init__(self, runner, mlist, msg, metadata, error):
+ self.runner = runner
+ self.mailing_list = mlist
+ self.message = msg
+ self.metadata = metadata
+ self.error = error
+
+
+
class IRunner(Interface):
"""The runner."""