Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the API #5

Merged
merged 3 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/two_phase_commit.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
defmodule TwoPhaseCommit do
@moduledoc """
`TwoPhaseCommit` is a library to execute actions in a fault tolerant manner by applying a two-phase-commit pattern for the business logic of the action and for the persistance layer.

It is mainly defined by thwo behaviours:
* `TwoPhaseCommit.Action` for the business logic, and
* `TwoPhaseCommit.Store` for the persistance layer.
"""

@type store :: module()
@type action :: module()
@type ref :: any()
Expand Down
17 changes: 17 additions & 0 deletions lib/two_phase_commit/action.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
defmodule TwoPhaseCommit.Action do
@moduledoc """
The action specification.

An action defines the business logic that is executed in a two-phase-commit approch. A module providing the busness logic must export the folloing two functions:
* a `prepare/2` function that prepares the execution of the businses logic, and
* a `commit/2` function that executes the business logic.

Calling the two functions after each other will run the business logic and return the result.

with {:ok, transaction} <- prepare(state, args),
{:ok, new_state, result} <- commit(state, transaction) do
{:ok, new_state, result}
end

Splitting the business logic into the _prepare_ and the _commit_ allows persiting the transaction before commiting the action to be able to recover in case of an failure. Therefore the transaction must contain the all data required to execute the action and to identify an potential previous execution. For example the transaction might contain all request parameters together with a unique request_id. This request_id allows identifying the request at the 3rd party.
"""

@type t :: module()

@type state :: term()
Expand Down
5 changes: 5 additions & 0 deletions lib/two_phase_commit/store.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
defmodule TwoPhaseCommit.Store do
@moduledoc """
The store specification.

A store defines the persistance layer for actions executed in a two-phase-commit approch.
"""
@type t :: module()

@type ref :: any()
Expand Down