Skip to content

Commit 93eb0cf

Browse files
committed
Move Supervisor methods around to prepare for async supervisor
That won't run a loop for supervise, it'll just start the processes and the maintenance task.
1 parent 347451c commit 93eb0cf

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

lib/solid_queue/processes/callbacks.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,5 @@ module Callbacks
88
extend ActiveModel::Callbacks
99
define_model_callbacks :boot, :shutdown
1010
end
11-
12-
private
13-
def boot
14-
end
15-
16-
def shutdown
17-
end
1811
end
1912
end

lib/solid_queue/processes/poller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def poll
3939
raise NotImplementedError
4040
end
4141

42+
def shutdown
43+
end
44+
4245
def with_polling_volume
4346
if SolidQueue.silence_polling? && ActiveRecord::Base.logger
4447
ActiveRecord::Base.logger.silence { yield }

lib/solid_queue/supervisor.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@ def initialize(configuration)
1818
end
1919

2020
def start
21-
run_callbacks(:boot) { boot }
21+
boot
2222

2323
start_processes
2424
launch_maintenance_task
2525

26-
loop do
27-
break if stopped?
28-
29-
supervise
30-
end
31-
ensure
32-
run_callbacks(:shutdown) { shutdown }
26+
supervise
3327
end
3428

3529
def stop
@@ -40,8 +34,10 @@ def stop
4034
attr_reader :configuration
4135

4236
def boot
43-
@stopped = false
44-
sync_std_streams
37+
run_callbacks(:boot) do
38+
@stopped = false
39+
sync_std_streams
40+
end
4541
end
4642

4743
def start_processes
@@ -53,15 +49,16 @@ def stopped?
5349
end
5450

5551
def supervise
56-
raise NotImplementedError
5752
end
5853

5954
def start_process(configured_process)
6055
raise NotImplementedError
6156
end
6257

6358
def shutdown
64-
stop_maintenance_task
59+
run_callbacks(:shutdown) do
60+
stop_maintenance_task
61+
end
6562
end
6663

6764
def sync_std_streams

lib/solid_queue/supervisor/fork_supervisor.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ def kind
1717
attr_reader :forks
1818

1919
def supervise
20-
procline "supervising #{forks.keys.join(", ")}"
21-
process_signal_queue
20+
loop do
21+
break if stopped?
22+
23+
procline "supervising #{forks.keys.join(", ")}"
24+
process_signal_queue
2225

23-
unless stopped?
24-
reap_and_replace_terminated_forks
25-
interruptible_sleep(1.second)
26+
unless stopped?
27+
reap_and_replace_terminated_forks
28+
interruptible_sleep(1.second)
29+
end
2630
end
31+
ensure
32+
shutdown
2733
end
2834

2935
def start_process(configured_process)

0 commit comments

Comments
 (0)