summaryrefslogtreecommitdiff
path: root/Mailman/queue/docs/runner.txt
blob: 5e5a88d8cb13871734365051ebe2533c68e9c321 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Queue runners
=============

The queue runners (qrunner) are the processes that move messages around the
Mailman system.  Each qrunner is responsible for a slice of the hash space in
a queue directory.  It processes all the files in its slice, sleeps a little
while, then wakes up and runs through its queue files again.


Basic architecture
------------------

The basic architecture of qrunner is implemented in the base class that all
runners inherit from.  This base class implements a .run() method that runs
continuously in a loop until the .stop() method is called.

    >>> import os
    >>> from Mailman.queue import Runner, Switchboard
    >>> from Mailman.configuration import config
    >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
    >>> mlist.preferred_language = u'en'

Here is a very simple derived qrunner class.  The class attribute QDIR tells
the qrunner which queue directory it is responsible for.  Derived classes
should also implement various methods to provide the special functionality.
This is about as simple as a qrunner can be.

    >>> queue_directory = os.path.join(config.QUEUE_DIR, 'test')
    >>> class TestableRunner(Runner):
    ...     QDIR = queue_directory
    ...
    ...     def _dispose(self, mlist, msg, msgdata):
    ...         self.msg = msg
    ...         self.msgdata = msgdata
    ...         return False
    ...
    ...     def _doperiodic(self):
    ...         self.stop()
    ...
    ...     def _snooze(self, filecnt):
    ...         return

    >>> runner = TestableRunner()
    >>> switchboard = Switchboard(queue_directory)

This qrunner doesn't do much except run once, storing the message and metadata
on instance variables.

    >>> msg = message_from_string(u"""\
    ... From: aperson@example.com
    ... To: _xtest@example.com
    ...
    ... A test message.
    ... """)
    >>> filebase = switchboard.enqueue(msg, listname=mlist.fqdn_listname,
    ...                                foo='yes', bar='no')
    >>> runner.run()
    >>> print runner.msg.as_string()
    From: aperson@example.com
    To: _xtest@example.com
    <BLANKLINE>
    A test message.
    <BLANKLINE>
    >>> sorted(runner.msgdata.items())
    [('_parsemsg', False),
     ('bar', 'no'), ('foo', 'yes'),
     ('lang', u'en'), ('listname', u'_xtest@example.com'),
     ('received_time', ...), ('version', 3)]

XXX More of the Runner API should be tested.