开发者

Ruby ActiveRecord Retryable

开发者 https://www.devze.com 2023-03-01 21:46 出处:网络
I am writing a ruby script that connects to an external Database and I am trying to write a retry script that upon disconnect (for whatever god-forsaken reason) will continue retrying to connect for e

I am writing a ruby script that connects to an external Database and I am trying to write a retry script that upon disconnect (for whatever god-forsaken reason) will continue retrying to connect for either a 开发者_运维问答specific number of retries or will die.

I know how to write the retryable piece into my script, the issue I am having is that I can't find the specific connection error in AR... anyone have a clue on this piece?


How about the ConnectionNotEstablished error?

  # Raised when connection to the database could not been established 
  # (for example when <tt>connection=</tt>
  # is given a nil object).
  class ConnectionNotEstablished < ActiveRecordError
  end

You will know that the database has been disconnected if this error appears out of the blue when you execute some command against the database (select statement, etc.). From there you can retry to connect (and execute the statement) a given number of times.

I found this ActiveRecord error here:

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/errors.rb

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号