Skip to content
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

fix: prevent duplicate configuration lines in production.rb #349

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions lib/generators/solid_queue/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ def copy_files
end

def configure_active_job_adapter
production_rb = Pathname(destination_root).join("config/environments/production.rb")

# Replace or set `config.active_job.queue_adapter`
gsub_file Pathname(destination_root).join("config/environments/production.rb"),
/config\.active_job\.queue_adapter\s+=.*/,
"config.active_job.queue_adapter = :solid_queue"

# Inject `config.solid_queue.connects_to` if not already present
gsub_file Pathname(destination_root).join("config/environments/production.rb"),
/(# )?config\.active_job\.queue_adapter\s+=.*/,
"config.active_job.queue_adapter = :solid_queue\n" +
" config.solid_queue.connects_to = { database: { writing: :queue } }\n"
/^\s*config\.solid_queue\.connects_to\s+=\s+\{.*\}\n/,
"",
verbose: false # If found, do nothing

inject_into_file Pathname(destination_root).join("config/environments/production.rb"),
"\n config.solid_queue.connects_to = { database: { writing: :queue } }",
after: /config\.active_job\.queue_adapter\s+=.*/
end
end