module Que::Utils::Transactions

Public Instance Methods

transaction() { || ... } click to toggle source
# File lib/que/utils/transactions.rb, line 11
def transaction
  pool.checkout do
    if pool.in_transaction?
      yield
    else
      begin
        execute "BEGIN"
        yield
      rescue => error
        raise
      ensure
        # Handle a raised error or a killed thread.
        if error || Thread.current.status == 'aborting'
          execute "ROLLBACK"
        else
          execute "COMMIT"
        end
      end
    end
  end
end