Method: Neo4j::Transaction#run

Defined in:
lib/neo4j/transaction.rb

#run(*args) ⇒ Object

Runs the given block in a new transaction. @@yield [Neo4j::Transaction::Instance]

Parameters:

  • run_in_tx (Boolean)

    if true a new transaction will not be created, instead if will simply yield to the given block



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/neo4j/transaction.rb', line 127

def run(*args)
  session, run_in_tx = session_and_run_in_tx_from_args(args)

  fail ArgumentError, 'Expected a block to run in Transaction.run' unless block_given?

  return yield(nil) unless run_in_tx

  tx = Neo4j::Transaction.new(session)
  yield tx
rescue Exception => e # rubocop:disable Lint/RescueException
  # print_exception_cause(e)

  tx.mark_failed unless tx.nil?
  raise e
ensure
  tx.close unless tx.nil?
end