Sha256: 2de3aef5cefc590ed071d1754913533adf68dec5cb294f1ef3bf88b45d26ce1b
Contents?: true
Size: 1.14 KB
Versions: 7
Compression:
Stored size: 1.14 KB
Contents
# frozen_string_literal: true module TrxExt # Implements the feature that allows you to define callbacks that will be fired after SQL transaction is complete. module Transaction # See https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-transaction # for available params def transaction(**kwargs, &blk) pool = nil TrxExt::Retry.retry_until_serialized do super(**kwargs) do pool = TrxExt::CallbackPool.add(previous: current_callbacks_chain_link) self.current_callbacks_chain_link = pool blk.call(pool) end rescue self.current_callbacks_chain_link = nil raise end ensure pool.exec_callbacks_chain(connection: self) end # Returns the {TrxExt::CallbackPool} instance for the transaction that is being executed at the moment. def current_callbacks_chain_link @trx_callbacks_chain end # Set the {TrxExt::CallbackPool} instance for the transaction that is being executed at the moment. def current_callbacks_chain_link=(val) @trx_callbacks_chain = val end end end
Version data entries
7 entries across 7 versions & 1 rubygems