Skip to content

Instantly share code, notes, and snippets.

@kineticac
Created December 23, 2012 08:59
Show Gist options
  • Save kineticac/4362634 to your computer and use it in GitHub Desktop.
Save kineticac/4362634 to your computer and use it in GitHub Desktop.
Here are my configs for sidekiq
require 'sidekiq'
require 'autoscaler/sidekiq'
require 'autoscaler/heroku_scaler'
heroku = nil
if ENV['HEROKU_APP']
heroku = Autoscaler::HerokuScaler.new
end
Sidekiq.configure_server do |config|
if Rails.env.development?
config.redis = { :url => 'redis://localhost:6379', :size => 25 }
else
config.redis = { :url => ENV["OPENREDIS_URL"], :size => 25 }
ENV["REDIS_PROVIDER"] = "OPENREDIS_URL"
end
config.server_middleware do |chain|
if heroku
p "[Sidekiq] Running on Heroku, autoscaler is used"
chain.add(Autoscaler::Sidekiq::Server, heroku, 60) # 60 seconds timeout
else
p "[Sidekiq] Running locally, so autoscaler isn't used"
end
end
end
require 'sidekiq'
require 'autoscaler/sidekiq'
require 'autoscaler/heroku_scaler'
worker_processes 3
timeout 30
preload_app true
before_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
sleep 1
end
after_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
heroku = nil
if ENV['HEROKU_APP']
heroku = Autoscaler::HerokuScaler.new
end
Sidekiq.configure_client do |config|
if Rails.env.development?
config.redis = { :url => 'redis://localhost:6379', :namespace => 'prime', :size => 25 }
else
config.redis = { :url => ENV["OPENREDIS_URL"], :namespace => 'prime', :size => 25 }
end
if heroku
config.client_middleware do |chain|
chain.add Autoscaler::Sidekiq::Client, 'default' => heroku
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment