File tree Expand file tree Collapse file tree 4 files changed +26
-32
lines changed Expand file tree Collapse file tree 4 files changed +26
-32
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module Runnable
7
7
attr_writer :mode
8
8
9
9
def start
10
- @stopping = false
10
+ @stopped = false
11
11
12
12
SolidQueue . instrument ( :start_process , process : self ) do
13
13
run_callbacks ( :boot ) { boot }
@@ -21,7 +21,7 @@ def start
21
21
end
22
22
23
23
def stop
24
- @stopping = true
24
+ @stopped = true
25
25
@thread &.join
26
26
end
27
27
@@ -40,15 +40,15 @@ def boot
40
40
end
41
41
42
42
def shutting_down?
43
- stopping ? || supervisor_went_away? || finished?
43
+ stopped ? || supervisor_went_away? || finished?
44
44
end
45
45
46
46
def run
47
47
raise NotImplementedError
48
48
end
49
49
50
- def stopping ?
51
- @stopping
50
+ def stopped ?
51
+ @stopped
52
52
end
53
53
54
54
def finished?
Original file line number Diff line number Diff line change @@ -4,9 +4,6 @@ module SolidQueue
4
4
class Supervisor < Processes ::Base
5
5
include Maintenance
6
6
7
- class GracefulTerminationRequested < Interrupt ; end
8
- class ImmediateTerminationRequested < Interrupt ; end
9
-
10
7
class << self
11
8
def start ( mode : :fork , load_configuration_from : nil )
12
9
SolidQueue . supervisor = true
@@ -26,26 +23,35 @@ def start
26
23
start_processes
27
24
launch_maintenance_task
28
25
29
- supervise
30
- rescue GracefulTerminationRequested
31
- terminate_gracefully
32
- rescue ImmediateTerminationRequested
33
- terminate_immediately
26
+ loop do
27
+ break if stopped?
28
+
29
+ supervise
30
+ end
34
31
ensure
35
32
run_callbacks ( :shutdown ) { shutdown }
36
33
end
37
34
35
+ def stop
36
+ @stopped = true
37
+ end
38
+
38
39
private
39
40
attr_reader :configuration
40
41
41
42
def boot
43
+ @stopped = false
42
44
sync_std_streams
43
45
end
44
46
45
47
def start_processes
46
48
configuration . processes . each { |configured_process | start_process ( configured_process ) }
47
49
end
48
50
51
+ def stopped?
52
+ @stopped
53
+ end
54
+
49
55
def supervise
50
56
raise NotImplementedError
51
57
end
@@ -54,12 +60,6 @@ def start_process(configured_process)
54
60
raise NotImplementedError
55
61
end
56
62
57
- def terminate_gracefully
58
- end
59
-
60
- def terminate_immediately
61
- end
62
-
63
63
def shutdown
64
64
stop_maintenance_task
65
65
end
Original file line number Diff line number Diff line change @@ -17,10 +17,10 @@ def kind
17
17
attr_reader :forks
18
18
19
19
def supervise
20
- loop do
21
- procline "supervising #{ forks . keys . join ( ", " ) } "
20
+ procline "supervising #{ forks . keys . join ( ", " ) } "
21
+ process_signal_queue
22
22
23
- process_signal_queue
23
+ unless stopped?
24
24
reap_and_replace_terminated_forks
25
25
interruptible_sleep ( 1 . second )
26
26
end
Original file line number Diff line number Diff line change @@ -37,22 +37,16 @@ def process_signal_queue
37
37
def handle_signal ( signal )
38
38
case signal
39
39
when :TERM , :INT
40
- request_graceful_termination
40
+ stop
41
+ terminate_gracefully
41
42
when :QUIT
42
- request_immediate_termination
43
+ stop
44
+ terminate_immediately
43
45
else
44
46
SolidQueue . instrument :unhandled_signal_error , signal : signal
45
47
end
46
48
end
47
49
48
- def request_graceful_termination
49
- raise GracefulTerminationRequested
50
- end
51
-
52
- def request_immediate_termination
53
- raise ImmediateTerminationRequested
54
- end
55
-
56
50
def signal_processes ( pids , signal )
57
51
pids . each do |pid |
58
52
signal_process pid , signal
You can’t perform that action at this time.
0 commit comments