Add this line to your application's Gemfile:
gem "idle_rails_shutdown", git: "https://github.com/ekroon/idle_rails_shutdown.git", branch: "main"
And then execute:
$ bundle install
The gem works out of the box with default settings. It will monitor controller actions and shut down the application if no events are received for 1 minute.
You can configure the gem in an initializer:
# config/initializers/idle_rails_shutdown.rb
IdleRailsShutdown.configure do |config|
# How often to check if the application is healthy (default: 1 minute)
config.check_interval = 30.seconds
# How long to wait without events before shutting down (default: 1 minute)
config.shutdown_threshold = 1.minute
# Optional callable to run when the application is idle. When set, this will
# be executed instead of sending a SIGINT to the process.
# config.shutdown_callable = -> { system("flyctl", "machine", "suspend") }
# The callable can be given directly, as a method reference, or as a string.
# These are equivalent:
# config.shutdown_callable = MyModule::MyClass.method(:shutdown)
# config.shutdown_callable = "MyModule::MyClass.shutdown"
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests.
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/fly_rails_shutdown.
The gem is available as open source under the terms of the MIT License.