-
-
Save kivanio/10018394 to your computer and use it in GitHub Desktop.
This file contains 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
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 | |
This file contains 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
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