Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sequel::ThreadedConnectionPool
- def hold_with_extra_behavior(server=:default, &block)
- t = Thread.current
- begin
- hold_without_extra_behavior(server, &block)
- rescue Sequel::DatabaseDisconnectError => re
- t[:recover_count] ||= 0
- t[:recover_count] += 1
- if t[:recover_count] >= (ENV['CAPTURE_CONNECTION_RECOVERY_COUNT'] || 3).to_i
- msg = "Could not acquire new connection after [#{t[:recover_count]}] attempts. Error[#{re.message}]"
- $DB_LOG.error msg
- raise RuntimeError, msg
- else
- $DB_LOG.warn "Acquiring new connection after recoverable error[#{re.message}]"
- retry
- end
- ensure
- t[:recover_count] = nil
- end
- end
- alias_method :hold_without_extra_behavior, :hold unless method_defined?(:hold_without_extra_behavior)
- alias_method :hold, :hold_with_extra_behavior
- end
Add Comment
Please, Sign In to add comment