Last active
July 26, 2020 16:24
-
-
Save pigoz/8a93247f51b51f9b39e6 to your computer and use it in GitHub Desktop.
puma cluster mode + sidekiq
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
threads 1, 4 | |
workers 2 | |
preload_app! | |
environment 'development' | |
bind 'tcp://0.0.0.0:3000' | |
ssl_bind '127.0.0.1', '5002', { | |
key: 'doc/certs/server.key', | |
cert: 'doc/certs/server.crt' | |
} | |
file = File.expand_path('../hooks.rb', __FILE__) | |
instance_eval IO.read(file), file |
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
on_worker_boot do | |
puts "[puma] booting worker..." | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection | |
end | |
if defined?(Sidekiq) | |
Sidekiq.redis_quit if Sidekiq.respond_to?(:redis_quit) | |
Sidekiq.configure_client do |config| | |
config.redis = { | |
url: #..., | |
namespace: #... | |
} | |
end | |
end | |
Rails.cache.reconnect if Rails.cache.respond_to?(:reconnect) | |
end | |
on_restart do | |
puts "[puma] restarting server..." | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.connection.disconnect! | |
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
module Sidekiq | |
def self.redis_quit | |
return if @redis.nil? | |
@redis.shutdown { |conn| conn.quit } | |
@redis = nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment