Last active
April 5, 2016 23:13
-
-
Save kmayer/7aa814b385ea60666502b01d9c44fbec to your computer and use it in GitHub Desktop.
Puma plugin to stop via Redis on Heroku
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
# === Plugins === | |
require './lib/puma/plugin/redis_stop_puma' | |
plugin 'redis_stop_puma' |
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 'puma/plugin' | |
require 'redis' | |
Puma::Plugin.create do | |
def start(launcher) | |
hostname = ENV['DYNO'] | |
return unless hostname | |
redis = Redis.new(url: ENV.fetch('REDIS_URL', nil)) | |
return unless redis.ping == 'PONG' | |
in_background do | |
while true | |
sleep 2 | |
if message = redis.get("puma::restart::#{hostname}") | |
redis.del("puma::restart::#{hostname}") | |
$stderr.puts message | |
launcher.stop | |
break | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment