Created
August 17, 2014 17:16
-
-
Save rainerborene/2b1ad9ef92f450734f59 to your computer and use it in GitHub Desktop.
Sidekiq Initializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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