From c1258210b4a4174b04b361446de2dcc568400fa3 Mon Sep 17 00:00:00 2001 From: Rosa Gutierrez Date: Sat, 24 Aug 2024 22:06:57 +0200 Subject: [PATCH] Remove Puma plugin After discussing with DHH, we don't want to be tied to a particular server and this won't be the recommended way to run Solid Queue with Rails, so just remove the provided plugin. It can still be used but it just won't be provided directly by the gem. --- README.md | 9 +-- lib/solid_queue.rb | 1 - .../dummy/lib}/puma/plugin/solid_queue.rb | 15 +++++ test/integration/puma/plugin_test.rb | 56 ------------------- 4 files changed, 17 insertions(+), 64 deletions(-) rename {lib => test/dummy/lib}/puma/plugin/solid_queue.rb (68%) delete mode 100644 test/integration/puma/plugin_test.rb diff --git a/README.md b/README.md index a1714eab..c8146b12 100644 --- a/README.md +++ b/README.md @@ -298,13 +298,8 @@ failed_execution.discard # This will delete the job from the system However, we recommend taking a look at [mission_control-jobs](https://github.com/rails/mission_control-jobs), a dashboard where, among other things, you can examine and retry/discard failed jobs. -## Puma plugin -We provide a Puma plugin if you want to run the Solid Queue's supervisor together with Puma and have Puma monitor and manage it. You just need to add -```ruby -plugin :solid_queue -``` -to your `puma.rb` configuration. - +## Running with Puma +You can use [a plugin](https://gist.github.com/rosa/ca8fde4bee5a2734dc3a31c89c3d26cd) to run the Solid Queue's supervisor together with Puma and have Puma monitor and manage it. ## Jobs and transactional integrity :warning: Having your jobs in the same ACID-compliant database as your application data enables a powerful yet sharp tool: taking advantage of transactional integrity to ensure some action in your app is not committed unless your job is also committed. This can be very powerful and useful, but it can also backfire if you base some of your logic on this behaviour, and in the future, you move to another active job backend, or if you simply move Solid Queue to its own database, and suddenly the behaviour changes under you. diff --git a/lib/solid_queue.rb b/lib/solid_queue.rb index c1b727c7..f994695e 100644 --- a/lib/solid_queue.rb +++ b/lib/solid_queue.rb @@ -14,7 +14,6 @@ loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false) loader.ignore("#{__dir__}/solid_queue/tasks.rb") loader.ignore("#{__dir__}/generators") -loader.ignore("#{__dir__}/puma") loader.setup module SolidQueue diff --git a/lib/puma/plugin/solid_queue.rb b/test/dummy/lib/puma/plugin/solid_queue.rb similarity index 68% rename from lib/puma/plugin/solid_queue.rb rename to test/dummy/lib/puma/plugin/solid_queue.rb index eca5fa5f..72cb0366 100644 --- a/lib/puma/plugin/solid_queue.rb +++ b/test/dummy/lib/puma/plugin/solid_queue.rb @@ -1,3 +1,18 @@ +# A plugin you can use if you want to run the Solid Queue's supervisor together with Puma and have Puma monitor +# and manage it. You just need to copy the plugin to lib/puma/plugin/solid_queue.rb and then add +# plugin :solid_queue +# to your `puma.rb` configuration. +# +# By default, the Puma plugin will fork additional processes for each worker and dispatcher so that they run in +# different processes. This provides the best isolation and performance, but can have additional memory usage. +# Alternatively, workers and dispatchers can be run within the same Puma process(s). To do so just +# configure the plugin as: +# +# plugin :solid_queue +# solid_queue_mode :async +# +# Note that in this case, the `processes` configuration option will be ignored. +# require "puma/plugin" Puma::Plugin.create do diff --git a/test/integration/puma/plugin_test.rb b/test/integration/puma/plugin_test.rb deleted file mode 100644 index 5826b57e..00000000 --- a/test/integration/puma/plugin_test.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class PluginTest < ActiveSupport::TestCase - self.use_transactional_tests = false - - setup do - FileUtils.mkdir_p Rails.root.join("tmp", "pids") - Dir.chdir("test/dummy") do - 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) if process_exists?(@pid) - wait_for_registered_processes 0, timeout: 2.seconds - end - - test "perform jobs inside puma's process" do - 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 - - test "stop the queue on puma's restart" do - signal_process(@pid, :SIGUSR2) - # Ensure the restart finishes before we try to continue with the test - wait_for_registered_processes(0, timeout: 3.second) - 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 - - test "stop puma when solid queue's supervisor dies" do - supervisor = find_processes_registered_as("Supervisor").first - - signal_process(supervisor.pid, :KILL) - wait_for_process_termination_with_timeout(@pid) - - assert_not process_exists?(@pid) - end -end