From b8290364f420acd8b87163fd5b824b0e84315d45 Mon Sep 17 00:00:00 2001 From: Rosa Gutierrez Date: Tue, 3 Dec 2024 20:01:15 +0100 Subject: [PATCH] Don't add `solid_queue.connects_to` configuration more than once Or, in other words, make the install generator idempotent. Inspired by #349 --- lib/generators/solid_queue/install/install_generator.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/generators/solid_queue/install/install_generator.rb b/lib/generators/solid_queue/install/install_generator.rb index 3d57391b..353b1094 100644 --- a/lib/generators/solid_queue/install/install_generator.rb +++ b/lib/generators/solid_queue/install/install_generator.rb @@ -11,9 +11,11 @@ def copy_files chmod "bin/jobs", 0755 & ~File.umask, verbose: false end - def configure_active_job_adapter - gsub_file Pathname(destination_root).join("config/environments/production.rb"), - /(# )?config\.active_job\.queue_adapter\s+=.*/, + def configure_adapter_and_database + pathname = Pathname(destination_root).join("config/environments/production.rb") + + gsub_file pathname, /\n\s*config\.solid_queue\.connects_to\s+=.*\n/, "\n", verbose: false + gsub_file pathname, /(# )?config\.active_job\.queue_adapter\s+=.*\n/, "config.active_job.queue_adapter = :solid_queue\n" + " config.solid_queue.connects_to = { database: { writing: :queue } }\n" end