Skip to content

Instantly share code, notes, and snippets.

@rainerborene
Created August 17, 2014 17:16
Show Gist options
  • Save rainerborene/2b1ad9ef92f450734f59 to your computer and use it in GitHub Desktop.
Save rainerborene/2b1ad9ef92f450734f59 to your computer and use it in GitHub Desktop.
Sidekiq Initializer
module Platform
module Database
def connect(size=35)
config = ActiveRecord::Base.configurations[Rails.env]
config['pool'] = ENV['DB_POOL'] || size
ActiveRecord::Base.establish_connection(config)
end
def disconnect
ActiveRecord::Base.connection_pool.disconnect!
end
def reconnect(size)
disconnect
connect(size)
end
module_function :disconnect, :connect, :reconnect
end
end
Rails.application.config.after_initialize do
ActiveSupport.on_load(:active_record) do
Sidekiq.configure_server do |config|
size = Sidekiq.options[:concurrency]
Platform::Database.reconnect(size)
config.server_middleware do |chain|
chain.add Sidekiq::Middleware::Server::Rescue
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment