-
Notifications
You must be signed in to change notification settings - Fork 41
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
Easier way to add pre-defined stages #46
Comments
Hey @ssbb, Im not sure that I understood the question, can you please give a real life use case (with more code) and Ill think how we can improve Sage in this direction? Thank you 🙏. |
Hi @AndrewDryga, we discussed this in Slack actually. My code looks like this: def run(%DepositForm{} = deposit, user, transaction, application) do
result =
Sage.new()
|> Sage.run(:transaction, fn _effects, _params -> {:ok, transaction} end)
|> Sage.run(:application, fn _effects, _params -> {:ok, application} end)
|> process()
|> Sage.transaction(Repo, %{deposit: deposit, user: user})
case result do
{:ok, _, %{update_payment: payment}} ->
{:ok, payment}
{:error, %Stripe.Error{user_message: user_message, message: message}} ->
{:error, "Deposit error: #{user_message || message}"}
err ->
Sentry.capture_exception(nil, extra: %{error: err}, level: "error")
err
end
end
def skip(sage) do
Sage.run(sage, :deposit, fn _effects, _params ->
{:ok, nil}
end)
end
def process(sage) do
sage
|> create_payment
|> customer
|> charge
|> update_payment
|> deliver_email
|> deliver_slack
end Really I am ok with "fake" Basically it can be used 2 ways - via |
I have few sagas which can be used independently and in another more high-level sagas. Just curious what is the proper way to use shared arguments/stages with such workflow.
Right now I have two functions
process(%Sage{} = sage)
which running all stages andrun(...)
. So I assume required data always ineffects_so_far
. Forrun
function I pass accepted arguments into "fake" stages:What is proper way to do it?
The text was updated successfully, but these errors were encountered: