Skip to content

Instantly share code, notes, and snippets.

@pigoz
Last active July 26, 2020 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pigoz/8a93247f51b51f9b39e6 to your computer and use it in GitHub Desktop.
Save pigoz/8a93247f51b51f9b39e6 to your computer and use it in GitHub Desktop.
puma cluster mode + sidekiq
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
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
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