Represents a single TCC action in a distributed transaction.
Each action consists of three phases:
- Try: Reserve resources and validate
- Confirm: Commit the changes
- Cancel: Rollback and release resources
Summary
Functions
Returns true if the action is async.
Executes the Cancel phase of the action with retry logic.
Executes the Confirm phase of the action with retry logic.
Executes the Try phase of the action.
Creates a new TCC action.
Creates a new async TCC action.
Types
Functions
Returns true if the action is async.
Executes the Cancel phase of the action with retry logic.
Executes the Confirm phase of the action with retry logic.
Executes the Try phase of the action.
The try function can return:
{:ok, effects, params}- Success, continue to next action{:error, reason}- Error, trigger cancel phase (allows retry){:abort, reason}- Unrecoverable error, trigger cancel phase (no retry)
Creates a new TCC action.
Callbacks can be either anonymous functions or MFA tuples {Module, :function, args}.
When using MFA tuples, effects and params are prepended to the args list.
Examples
# Using anonymous functions
iex> TCC.Action.new(:payment, &try_fn/2, &confirm_fn/2, &cancel_fn/2)
%TCC.Action{name: :payment, ...}
# Using MFA tuples
iex> TCC.Action.new(:payment,
...> {PaymentService, :try_payment, []},
...> {PaymentService, :confirm_payment, []},
...> {PaymentService, :cancel_payment, []})
%TCC.Action{name: :payment, ...}
Creates a new async TCC action.
Async actions are executed in parallel during the Try phase. They are awaited before the next synchronous action or at the end of the Try phase.
Options
:timeout- Time in milliseconds to wait for the async action (default: 5000)
Example
TCC.new()
|> TCC.run_async(:payment, &try_fn/2, &confirm_fn/2, &cancel_fn/2, timeout: 10_000)