-
Notifications
You must be signed in to change notification settings - Fork 42
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
Return only map of effects after Saga execution is finished #33
Comments
@namxam so Yes, you would have a |
Should stage names be considered public API? By returning "raw" effects, Sage exposes the stage name to caller. That would be useful in some cases, but I think it's better to have a way to transform effects to return value, so that that "transformation" holds the public contract. I may wrap it like this def run_saga do
new()
|> run(:foo, &create_foo/2)
|> execute(opts)
|> transform_effects()
end
defp transform_effects() However, it would be nice if Sage has the built-in way to do this, like: def run_saga do
new()
|> run(:foo, &create_foo/2)
|> transform_effects(&my_transformer/1)
|> execute(opts)
end
defp my_transfomer(effects) |
@chulkilee So in your example, it looks like we only add syntax sugar and make Sage more complex and we don't save a single line of client code in a return. The code with explicit call looks more obvious for people that never worked with this library. The way how I would do it is to pipe Sage execution return to case, like this:
We used this pattern a lot with Ecto.Multi and Ecto transactions. |
That looks great! I thought BTW, if we switch |
@chulkilee can't we get the ordered stages from %Sage{} struct? to create a pattern to return and transmit events from https://github.com/otobus/event_bus (as recommended at #23) in order, I use something like: %{stages: stages} = sage = new()
|> run(:board, &create_board/2)
|> run(:task, &create_task/2)
{:ok, _, effects} = sage = new()
|> execute(opts)
# since stages is a reversed list, i don't need to revert the order at the end
stages
|> Enum.map(fn name, _ -> name end)
|> Enum.reduce([], fn(name, acc) ->
case Map.get(effects, name) do
{_, events} -> [{name, events} | acc]
_ -> acc
end
end) |
I am just trying Sage for the first time and therefore not sure if I am using it correctly.
When running a saga, its return value looks like:
{:ok, last_effect, effects}
. Wouldn't it make more sense to just return{:ok, effects}
. As from a consumer's point of view I do not want to know about which step was last and what it's result was.And where would I format / post process it. Would you put a case statement right after a saga's steps or where the saga is actually called?
The text was updated successfully, but these errors were encountered: