Skip to content

Instantly share code, notes, and snippets.

@ricardopadua
Last active July 21, 2022 00:28
Show Gist options
  • Save ricardopadua/30b51c7598552f79297740d9327f23dd to your computer and use it in GitHub Desktop.
Save ricardopadua/30b51c7598552f79297740d9327f23dd to your computer and use it in GitHub Desktop.
pipeline Ecto Multi
@spec pipeline(any) :: (() -> any)
def pipeline(params) do
create_operation = fn (multi, params) ->
Ecto.Multi.run(multi, :create_operation, fn _, _ ->
Logger.info("create_operation")
{:ok, nil}
end)
end
verify_condition = fn (multi, params) ->
Ecto.Multi.run(multi, :verify_condition, fn _, _ ->
Logger.info("verify_condition")
{:ok, nil}
end)
end
other_create_operation = fn (multi, params) ->
Ecto.Multi.run(multi, :other_create_operation, fn _, _ ->
Logger.info("other_create_operation")
{:ok, nil}
end)
end
other_verify_condition = fn (multi, params) ->
Ecto.Multi.run(multi, :other_verify_condition, fn _, _ ->
Logger.info("other_verify_condition")
{:ok, nil}
end)
end
fn ->
Ecto.Multi.new()
|> create_operation.(params)
|> verify_condition.(params)
|> other_create_operation.(params)
|> other_verify_condition.(params)
|> Repo.transaction()
|> Tracing.set_error()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment