1

I have a Rails application in which the vast majority of requests do not use ActiveRecord in any way. It would be nice if the rest of the application worked seamlessly when MySQL was unavailable. However, it seems that on each request, ActiveRecord::Base.verify_active_connections! is called. This means that every endpoint breaks, when really just the ones that use ActiveRecord need to break. How can I configure things so that the actions that do not require ActiveRecord will work fine in the absence of MySQL?

lacker
  • 5,470
  • 6
  • 36
  • 38

1 Answers1

2

Override it!

class ActiveRecord::Base
  def self.verify_active_connections!
    begin
       super
    rescue
      puts "Do something"
    end
   end
 end

Probably not the best idea to just do a blanket begin/rescue but you get the point. For more information check this question out: "MySQL server has gone away" with Ruby on Rails

Community
  • 1
  • 1
Erik Petersen
  • 2,347
  • 14
  • 17