I\'d like to have some cleanup code run when Rails is shutting down - is that possible? My situation is that I have a few threads in the background (I\'m using jruby and ca
Within the context of a Rails Application, the best place to put such a file is in config/initializers. In my app, I needed to Flush the Redis/Sidekiq queue whenever the development or test environments shut down. This works perfectly.
at_exit do
begin
puts 'Flushing Redis...'
Redis.new.flushall
rescue => e
puts "There was an #{e.to_s} while flushing redis..."
ensure
puts 'Done Flushing Redis!'
end
end unless Rails.env.production?