Last active
August 6, 2019 16:37
-
-
Save j4rs/3a39dd2568d0b618ae3c5876ed0e77a6 to your computer and use it in GitHub Desktop.
Signal Heroku - from your codebase - to restart the dynos.
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
# This snippet can be included in ApplicationController.rb | |
if Rails.env.production? | |
rescue_from StandardError do |error| | |
# if it is an unrecoverable error, send a signal to heroku | |
# to restart the infrastructure | |
if error.message =~ /deadlock; recursive locking/ | |
hclient = PlatformAPI.connect_oauth(ENV["HEROKU_API_TOKEN"]) | |
heroku_app, dyno = "name-of-your-app", hclient.dyno | |
# avoid sending the signal more than once | |
if dyno.list(heroku_app).dig(0, "state") === "up" | |
heroku_app.restart_all(heroku_app) | |
end | |
end | |
server_error | |
end | |
end | |
def server_error | |
render "common/500", status: :internal_server_error | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment