module CollectiveIdea::Acts::NestedSet::Model::Transactable
Protected Instance Methods
in_tenacious_transaction(&block)
click to toggle source
# File lib/awesome_nested_set/model/transactable.rb 13 def in_tenacious_transaction(&block) 14 retry_count = 0 15 begin 16 transaction(&block) 17 rescue CollectiveIdea::Acts::NestedSet::Move::ImpossibleMove 18 raise 19 rescue ActiveRecord::StatementInvalid => error 20 raise OpenTransactionsIsNotZero.new(error.message) unless self.class.connection.open_transactions.zero? 21 raise unless error.message =~ /[Dd]eadlock|Lock wait timeout exceeded/ 22 raise DeadlockDetected.new(error.message) unless retry_count < 10 23 retry_count += 1 24 logger.info "Deadlock detected on retry #{retry_count}, restarting transaction" 25 sleep(rand(retry_count)*0.1) # Aloha protocol 26 retry 27 end 28 end