-
-
Save tskogberg/c7cbd42008f8ec8fd920817a2229cf33 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby | |
APP_PATH = File.expand_path("../../config/application", __FILE__) | |
require_relative "../config/boot" | |
# Make a clean exit on Heroku while running a rails console. | |
# Without this we'll get a "SignalException: SIGHUP" error in honeybadger. | |
if ENV["DYNO"] | |
if ["c", "console"].include?(ARGV.first) | |
Signal.trap("SIGHUP") { exit 0 } | |
end | |
end | |
require "rails/commands" |
@taylorbrooks i think this goes into bin/rails
@tskogberg thank you for this script, I just used it and worked like a charm! 👏
this works only with heroku?
I work with @tskogberg and can confirm we've put this in bin/rails
. Our current bin/rails
with Rails 5.2 is
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError => e
raise unless e.message.include?("spring")
end
followed by the code above (except for its hashbang).
We've only tried this with Heroku but it may work on other platforms if they set ENV["DYNO"] and work in a similar way. Please write a comment if you try it.
I implemented this piece of code in July 2023 on a Rails 6 app (in bin/rails as suggested). It worked nicely. No more errors. But after some time the errors returned. I can see I upgraded to Rails 7 in August 2023 and around this time the errors returned. Possibly related?
I just checked again today:
Rails 7 app, fix code as shown above, implemented in bin/rails
$heroku run rails c
(left alone for 1 hour)
irb(main):001:0> Error: timed out
$heroku logs
...Process exited with status 129
and HoneyBadger reported a SignalException: SIGHUP error
@tskogberg Where did you put this code? In an initializer?