Skip to content

Stop SolidQueue on puma restart when puma plugin is used. #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/puma/plugin/solid_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def start(launcher)
end

launcher.events.on_stopped { stop_solid_queue }
launcher.events.on_restart { stop_solid_queue }
end

private
Expand Down
35 changes: 23 additions & 12 deletions test/integration/puma/plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ class PumaPluginTest < ActiveSupport::TestCase
setup do
FileUtils.mkdir_p Rails.root.join("tmp", "pids")

cmd = %w[
bundle exec puma
-b tcp://127.0.0.1:9222
-C test/dummy/config/puma.rb
--dir test/dummy
-s
config.ru
]

@pid = fork do
exec(*cmd)
Dir.chdir('test/dummy') do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change the dir here this way instead of using --dir option because when you trigger puma's restart it can't find the app anymore since current dir is already test/dummy and it's trying to use test/dummy in addition.

cmd = %w[
bundle exec puma
-b tcp://127.0.0.1:9222
-C config/puma.rb
-s
config.ru
]

@pid = fork do
exec(*cmd)
end
end

wait_for_registered_processes(4, timeout: 3.second)
end

teardown do
terminate_process(@pid, signal: :INT)
wait_for_registered_processes 0, timeout: 0.2.second
wait_for_registered_processes 0, timeout: 1.second

JobResult.delete_all
end
Expand All @@ -36,4 +37,14 @@ class PumaPluginTest < ActiveSupport::TestCase
wait_for_jobs_to_finish_for(1.second)
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
end

test "stop the queue on puma's restart" do
signal_process(@pid, :SIGUSR2)

wait_for_registered_processes(4, timeout: 3.second)

StoreResultJob.perform_later(:puma_plugin)
wait_for_jobs_to_finish_for(2.seconds)
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
end
end
Loading