Nebo15 / sage

A dependency-free tool to run distributed transactions in Elixir, inspired by Sagas pattern.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create a savepoint for each step and rollback to it when Sage is wrapped in Ecto transaction

AndrewDryga opened this issue · comments

There is a logical flaw in current Sage version, imagine that we have a transaction that inserts something in the database and no compensation for it (because the effect would be rolled back on transaction abort). If there is a retry on one of preceding steps to it - we may insert multiple records and succeed.

Fortunately, it's pretty easy to implement. We need to support transaction execution adapter which works similarly to inspection adapter and is called each time we want to apply or compensate a step. The adapter needs to take care of wrapping the sage and executing it. Additionally, it should allow executing code after it's committed (for #23).

In future, we would need something like sage_ecto package (which can be built in with if Code.ensure_loaded?(Ecto) for now).