Skip to content

Commit bc96173

Browse files
committed
Stop SolidQueue on puma restart when puma plugin is used.
Without doing so SolidQueue would be running making Puma not properly stop so whne Puma tries to start its process again we would get `Errno::EADDRINUSE` error.
1 parent 50b29d4 commit bc96173

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

lib/puma/plugin/solid_queue.rb

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def start(launcher)
1919
end
2020

2121
launcher.events.on_stopped { stop_solid_queue }
22+
launcher.events.on_restart { stop_solid_queue }
2223
end
2324

2425
private

test/integration/puma/plugin_test.rb

+27-12
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,32 @@
44
class PumaPluginTest < ActiveSupport::TestCase
55
self.use_transactional_tests = false
66

7+
def puma_pid
8+
File.read(Rails.root.join('tmp', 'pids', 'server.pid')).to_i
9+
end
10+
711
setup do
812
FileUtils.mkdir_p Rails.root.join("tmp", "pids")
913

10-
cmd = %w[
11-
bundle exec puma
12-
-b tcp://127.0.0.1:9222
13-
-C test/dummy/config/puma.rb
14-
--dir test/dummy
15-
-s
16-
config.ru
17-
]
18-
19-
@pid = fork do
20-
exec(*cmd)
14+
Dir.chdir('test/dummy') do
15+
cmd = %w[
16+
bundle exec puma
17+
-b tcp://127.0.0.1:9222
18+
-C config/puma.rb
19+
-s
20+
config.ru
21+
]
22+
23+
fork do
24+
exec(*cmd)
25+
end
2126
end
2227

2328
wait_for_registered_processes(4, timeout: 3.second)
2429
end
2530

2631
teardown do
27-
terminate_process(@pid, signal: :INT)
32+
terminate_process(puma_pid, signal: :INT)
2833
wait_for_registered_processes 0, timeout: 0.2.second
2934

3035
JobResult.delete_all
@@ -36,4 +41,14 @@ class PumaPluginTest < ActiveSupport::TestCase
3641
wait_for_jobs_to_finish_for(1.second)
3742
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
3843
end
44+
45+
test "stop the queue on puma's restart" do
46+
signal_process(puma_pid, :SIGUSR2)
47+
48+
wait_for_registered_processes(4, timeout: 3.second)
49+
50+
StoreResultJob.perform_later(:puma_plugin)
51+
wait_for_jobs_to_finish_for(1.second)
52+
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
53+
end
3954
end

0 commit comments

Comments
 (0)