DoubleEntryLedger.Occ.Occable protocol (double_entry_ledger v0.1.0)

View Source

Protocol 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:

  1. Updating entities during retry attempts when conflicts occur
  2. 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

Types

t()

All the types that implement this protocol.

Functions

Handles the timeout scenario when maximum OCC retries are reached.

Updates the entity with retry information during OCC retry cycles.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

build_multi(impl_struct)

@spec build_multi(t()) :: Ecto.Multi.t()

timed_out(impl_struct, name, error_map)

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 protocol
  • error_map - Map containing retry count and accumulated errors
  • repo - Ecto.Repo to use for the update operation

Returns

  • A tuple containing error details and the final state of the entity

update!(impl_struct, error_map, repo)

@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 protocol
  • error_map - Map containing retry count and error details
  • repo - Ecto.Repo to use for the update operation

Returns

  • The updated struct with retry information