DoubleEntryLedger.Occ.Occable protocol (double_entry_ledger v0.1.0)
View SourceProtocol for handling Optimistic Concurrency Control (OCC) in the double-entry ledger system.
This protocol defines the behavior required for entities that use optimistic concurrency control for database operations. It provides methods for:
- Updating entities during retry attempts when conflicts occur
- Handling timeout situations when maximum retries are reached
Implementing this protocol allows an entity to participate in the OCC process with standardized error handling and retry mechanisms.
Summary
Functions
Handles the timeout scenario when maximum OCC retries are reached.
Updates the entity with retry information during OCC retry cycles.
Types
@type t() :: term()
All the types that implement this protocol.
Functions
@spec build_multi(t()) :: Ecto.Multi.t()
@spec timed_out(t(), atom(), DoubleEntryLedger.Command.ErrorMap.t()) :: Ecto.Multi.t()
Handles the timeout scenario when maximum OCC retries are reached.
When the system has attempted the configured maximum number of retries and still encounters conflicts, this function is called to finalize the entity state and return an appropriate error tuple.
Parameters
impl_struct- The struct implementing this protocolerror_map- Map containing retry count and accumulated errorsrepo- Ecto.Repo to use for the update operation
Returns
- A tuple containing error details and the final state of the entity
@spec update!(t(), DoubleEntryLedger.Command.ErrorMap.t(), Ecto.Repo.t()) :: t()
Updates the entity with retry information during OCC retry cycles.
When an optimistic concurrency conflict is detected, this function is called to record the retry attempt and associated error information.
Parameters
impl_struct- The struct implementing this protocolerror_map- Map containing retry count and error detailsrepo- Ecto.Repo to use for the update operation
Returns
- The updated struct with retry information