Skip to content

Commit 35f0b35

Browse files
nashbyrosa
authored andcommitted
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 511f1ff commit 35f0b35

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-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

+23-12
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@ class PumaPluginTest < ActiveSupport::TestCase
77
setup do
88
FileUtils.mkdir_p Rails.root.join("tmp", "pids")
99

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)
10+
Dir.chdir('test/dummy') do
11+
cmd = %w[
12+
bundle exec puma
13+
-b tcp://127.0.0.1:9222
14+
-C config/puma.rb
15+
-s
16+
config.ru
17+
]
18+
19+
@pid = fork do
20+
exec(*cmd)
21+
end
2122
end
2223

2324
wait_for_registered_processes(4, timeout: 3.second)
2425
end
2526

2627
teardown do
2728
terminate_process(@pid, signal: :INT)
28-
wait_for_registered_processes 0, timeout: 0.2.second
29+
wait_for_registered_processes 0, timeout: 1.second
2930

3031
JobResult.delete_all
3132
end
@@ -36,4 +37,14 @@ class PumaPluginTest < ActiveSupport::TestCase
3637
wait_for_jobs_to_finish_for(1.second)
3738
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
3839
end
40+
41+
test "stop the queue on puma's restart" do
42+
signal_process(@pid, :SIGUSR2)
43+
44+
wait_for_registered_processes(4, timeout: 3.second)
45+
46+
StoreResultJob.perform_later(:puma_plugin)
47+
wait_for_jobs_to_finish_for(2.seconds)
48+
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
49+
end
3950
end

0 commit comments

Comments
 (0)