def start(&block)
      @attempts += 1

      with_transaction_state(&block)
    rescue ActiveRecord::StatementInvalid => error
      raise unless connection.open_transactions.zero?
      raise unless error.message =~ DEADLOCK_MESSAGES
      raise if attempts >= RETRY_COUNT

      logger.info "Deadlock detected on attempt #{attempts}, restarting transaction"

      pause and retry
    end
def start(&block)
      @attempts += 1

      with_transaction_state(&block)
    rescue ActiveRecord::StatementInvalid => error
      raise unless connection.open_transactions.zero?
      raise unless error.message =~ DEADLOCK_MESSAGES
      raise if attempts >= RETRY_COUNT

      logger.info "Deadlock detected on attempt #{attempts}, restarting transaction"

      pause and retry
    end
Starts persevering transaction