Skip to content

Commit

Permalink
Add database primary replica configuration for sidekiqs
Browse files Browse the repository at this point in the history
  • Loading branch information
praveendhawan committed Jan 8, 2024
1 parent a698ff8 commit e4932e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libraries/drivers_worker_sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sidekiq_custom/templates/default/sidekiq_database.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>

0 comments on commit e4932e0

Please sign in to comment.