diff --git a/libraries/drivers_worker_sidekiq.rb b/libraries/drivers_worker_sidekiq.rb index 35ff9db4..733d0899 100644 --- a/libraries/drivers_worker_sidekiq.rb +++ b/libraries/drivers_worker_sidekiq.rb @@ -133,6 +133,11 @@ def add_replica_config Chef::Log.info('Rewrite Sidekiq database.yml for read-replica') deploy = node['deploy'][app['shortname']] + database = deploy['database'] + replica_database = deploy['sidekiq_on_replica']&.dup + replica_database = database.dup if replica_database.nil? + replica_database[:replica] = true + Chef::Log.info(deploy.inspect) context.template "#{deploy_dir(app)}/shared/config/database.yml" do source 'sidekiq_database.yml.erb' @@ -141,9 +146,9 @@ def add_replica_config group node['deployer']['group'] owner node['deployer']['user'] variables( - database: deploy['database'], + database: database, environment: deploy['global']['environment'], - sidekiq_on_replica: deploy['sidekiq_on_replica'] + sidekiq_on_replica: replica_database, ) end end diff --git a/sidekiq_custom/templates/default/sidekiq_database.yml.erb b/sidekiq_custom/templates/default/sidekiq_database.yml.erb index d524580b..a2f81013 100644 --- a/sidekiq_custom/templates/default/sidekiq_database.yml.erb +++ b/sidekiq_custom/templates/default/sidekiq_database.yml.erb @@ -24,5 +24,8 @@ <%- if @sidekiq_on_replica[:port] -%> port: <%= @sidekiq_on_replica[:port].to_i.inspect %> <%- end -%> + <%- if @sidekiq_on_replica[:replica] -%> + replica: true + <%- end -%> <% end -%> <%- end -%>