Last active
July 21, 2022 00:28
-
-
Save ricardopadua/30b51c7598552f79297740d9327f23dd to your computer and use it in GitHub Desktop.
pipeline Ecto Multi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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