Transaction Strategy
The transaction strategy wraps your action execution in a database transaction:
ruby
class TransferFunds
include Axn
use :transaction
expects :from_account, :to_account, :amount
def call
from_account.withdraw!(amount)
to_account.deposit!(amount)
expose :transfer_id, SecureRandom.uuid
end
endImportant: The transaction wraps the entire action execution, including:
beforehooks- The main
callmethod afterhooks- Success/failure callbacks (
on_success,on_failure, etc.)
This means that if any part of the action (including hooks or callbacks) raises an exception or calls fail!, the entire transaction will be rolled back.
Requirements: Requires ActiveRecord to be available in your application.