sage v0.1.0 Sage.Experimental behaviour

This module described experimental features planned for Sage.

Link to this section Summary

Callbacks

Appends sage with an checkpoint at which forward retries should occur

Appends sage with an cached transaction and function to compensate it’s side effects

Appends sage with an asynchronous cached transaction and function to compensate it’s side effects

Appends sage with an cached transaction and function to compensate it’s side effects

Register persistent adapter and idempotency key generator to make it possible to re-run same requests idempotently (by either replying with old success response or continuing from the latest failed Sage transaction)

Link to this section Callbacks

Link to this callback checkpoint(sage, retry_opts)
checkpoint(sage :: Sage.t(), retry_opts :: retry_opts()) :: Sage.t()

Appends sage with an checkpoint at which forward retries should occur.

Internally this is the same as using:

retry_adapter = fn state -> if adapter.retry?(state, retry_opts) do {:retry, state} else {:ok, state} end

|> run(fn _ -> {:ok, :noop}, retry_adapter)

TODO: Also can be used as point of synchronization, eg.

  • to persist temporary state in a DB to idempotently retry it;
  • to ack previous execution stage to MQ and create a new one.

TODO: Rename to retry?

Link to this callback run_async(sage, apply, rollback, opts)
run_async(sage :: Sage.t(), apply :: Sage.transaction(), rollback :: Sage.compensation(), opts :: Keyword.t()) :: Sage.t()

Appends sage with an cached transaction and function to compensate it’s side effects.

sage
|> run_async(:a, tx_cb, cmp_cb)
|> run_async(:b, tx_cb, cmp_cb, after: :a)
|> run_async(:e, tx_cb, cmp_cb)
|> run_async(:c, tx_cb, cmp_cb, after: [:b, :e])

To implement this we need a run-time checks for dependency tree to get rid of dead ends and recursive dependencies before sage is executed.

Link to this callback run_async_cached(sage, apply, rollback, opts)
run_async_cached(sage :: Sage.t(), apply :: Sage.transaction(), rollback :: Sage.compensation(), opts :: cache_opts()) :: Sage.t()

Appends sage with an asynchronous cached transaction and function to compensate it’s side effects.

Next non-asynchronous operation will await for this function return.

Cache is stored by calling a Sage.CacheAdapter implementation.

Link to this callback run_cached(sage, apply, rollback, opts)
run_cached(sage :: Sage.t(), apply :: Sage.transaction(), rollback :: Sage.compensation(), opts :: cache_opts()) :: Sage.t()

Appends sage with an cached transaction and function to compensate it’s side effects.

Cache is stored by calling a Sage.CacheAdapter implementation.

Link to this callback with_idempotency(sage, adapter)
with_idempotency(sage :: Sage.t(), adapter :: module()) :: Sage.t()

Register persistent adapter and idempotency key generator to make it possible to re-run same requests idempotently (by either replying with old success response or continuing from the latest failed Sage transaction).