dennismonsewicz
dennismonsewicz

Reputation: 25542

Ruby ActiveRecord Retryable

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?

Upvotes: 1

Views: 542

Answers (1)

McStretch
McStretch

Reputation: 20665

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

Upvotes: 2

Related Questions