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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# Copyright (C) 2007-2009 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/>.
"""Interface for queue runners."""
from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
'IRunner',
]
from zope.interface import Interface, Attribute
class IRunner(Interface):
"""The queue runner."""
def run():
"""Start the queue runner."""
def stop():
"""Stop the queue runner on the next iteration through the loop."""
queue_directory = Attribute(
'The queue directory. Overridden in subclasses.')
sleep_time = Attribute("""\
The number of seconds this queue runner will sleep between iterations
through the main loop. If given, overrides
`config.QRUNNER_SLEEP_TIME`
""")
def _one_iteration():
"""The work done in one iteration of the main loop.
Can be overridden by subclasses.
:return: The number of files still left to process.
:rtype: int
"""
def _process_one_file(msg, msgdata):
"""Process one queue file.
:param msg: The message object.
:type msg: `email.message.Message`
:param msgdata: The message metadata.
:type msgdata: dict
"""
def _clean_up():
"""Clean up upon exit from the main processing loop.
Called when the queue runner's main loop is stopped, this should
perform any necessary resource deallocation.
"""
def _dispose(mlist, msg, msgdata):
"""Dispose of a single message destined for a mailing list.
Called for each message that the queue runner is responsible for, this
is the primary overridable method for processing each message.
Subclasses, must provide implementation for this method.
:param mlist: The mailing list this message is destined for.
:type mlist: `IMailingList`
:param msg: The message being processed.
:type msg: `email.message.Message`
:param msgdata: The message metadata.
:type msgdata: dict
:return: True if the message should continue to be queue, False if the
message should be deleted automatically.
:rtype: bool
"""
def _do_periodic():
"""Do some arbitrary periodic processing.
Called every once in a while both from the queue runner's main loop,
and from the runner's hash slice processing loop. You can do whatever
special periodic processing you want here.
"""
def _snooze(filecnt):
"""Sleep for a little while.
:param filecnt: The number of messages in the queue the last time
through. Queue runners can decide to continue to do work, or
sleep for a while based on this value. By default, the base queue
runner only snoozes when there was nothing to do last time around.
:type filecnt: int
"""
def _short_circuit():
"""Should processing be short-circuited?
:return: True if the file processing loop should exit before it's
finished processing each message in the current slice of hash
space. False tells _one_iteration() to continue processing until
the current snapshot of hash space is exhausted.
:rtype: bool
"""
|