File tree 5 files changed +46
-1
lines changed
5 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -242,3 +242,10 @@ loading will be disabled.
242
242
interfere with running Mailman with cron or as a daemon.
243
243
244
244
** Default** : ` false `
245
+
246
+ ### Graceful death
247
+
248
+ ` Mailman.config.graceful_death ` , if set, will catch SIGINTs
249
+ (Control-C) and allow the mail receiver to finish its current
250
+ iteration before exiting. Note that this currently only works
251
+ with POP3 receivers.
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ def self.run(&block)
15
15
attr_reader :processor
16
16
17
17
# Creates a new router, and sets up any routes passed in the block.
18
+ # @param [Hash] options the application options
19
+ # @option options [true,false] :graceful_death catch interrupt signal and don't die until end of poll
18
20
# @param [Proc] block a block with routes
19
21
def initialize ( &block )
20
22
@router = Mailman ::Router . new
@@ -52,6 +54,11 @@ def run
52
54
end
53
55
54
56
connection = Receiver ::POP3 . new ( options )
57
+
58
+ if Mailman . config . graceful_death
59
+ Signal . trap ( "INT" ) { polling = false }
60
+ end
61
+
55
62
loop do
56
63
begin
57
64
connection . connect
Original file line number Diff line number Diff line change @@ -21,7 +21,12 @@ class Configuration
21
21
# @return [boolean] whether or not to ignore stdin. Setting this to true
22
22
# stops Mailman from entering stdin processing mode.
23
23
attr_accessor :ignore_stdin
24
-
24
+
25
+ # @return [boolean] catch SIGINT and allow current iteration to finish
26
+ # rather than dropping dead immediately. Currently only works with POP3
27
+ # connections.
28
+ attr_accessor :graceful_death
29
+
25
30
def logger
26
31
@logger ||= Logger . new ( STDOUT )
27
32
end
Original file line number Diff line number Diff line change 18
18
19
19
end
20
20
21
+ describe "#run" do
22
+ describe "when graceful_death flag is set" do
23
+ before do
24
+ Mailman . config . graceful_death = true
25
+ @app = Mailman ::Application . new { }
26
+ end
27
+
28
+ it "should catch interrupt signal and let a POP3 receiver finish its poll before exiting" do
29
+ @mock_receiver = double ( "Receiver::POP3" )
30
+ @mock_receiver . stub ( :connect )
31
+ @mock_receiver . stub ( :get_messages ) { Process . kill ( "INT" , $$) }
32
+ @mock_receiver . should_receive ( :disconnect )
33
+ Mailman ::Receiver ::POP3 . stub ( :new ) { @mock_receiver }
34
+
35
+ Mailman . config . pop3 = { }
36
+
37
+ Signal . trap ( "INT" ) { raise "Application didn't catch SIGINT" }
38
+ @app . run
39
+ end
40
+ end
41
+ end
21
42
end
Original file line number Diff line number Diff line change 55
55
config . ignore_stdin = true
56
56
config . ignore_stdin . should == true
57
57
end
58
+
59
+ it "should store graceful_death flag" do
60
+ config . graceful_death = true
61
+ config . graceful_death . should == true
62
+ end
58
63
end
You can’t perform that action at this time.
0 commit comments