Guest User

Untitled

a guest
Oct 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class Sequel::ThreadedConnectionPool
  2. def hold_with_extra_behavior(server=:default, &block)
  3. t = Thread.current
  4.  
  5. begin
  6. hold_without_extra_behavior(server, &block)
  7. rescue Sequel::DatabaseDisconnectError => re
  8. t[:recover_count] ||= 0
  9. t[:recover_count] += 1
  10.  
  11. if t[:recover_count] >= (ENV['CAPTURE_CONNECTION_RECOVERY_COUNT'] || 3).to_i
  12. msg = "Could not acquire new connection after [#{t[:recover_count]}] attempts. Error[#{re.message}]"
  13. $DB_LOG.error msg
  14. raise RuntimeError, msg
  15. else
  16. $DB_LOG.warn "Acquiring new connection after recoverable error[#{re.message}]"
  17. retry
  18. end
  19. ensure
  20. t[:recover_count] = nil
  21. end
  22. end
  23.  
  24. alias_method :hold_without_extra_behavior, :hold unless method_defined?(:hold_without_extra_behavior)
  25. alias_method :hold, :hold_with_extra_behavior
  26. end
Add Comment
Please, Sign In to add comment