-
Notifications
You must be signed in to change notification settings - Fork 25
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
Binary state methods for custom outputs. #63
Comments
Hi @elShiaLabeouf, wow, you have lots of ideas, I like that! 💚 Regarding your specific requirement, my suggestion would be to enhance One important thing to keep in mind is that calling operations is a concept that will happen in an |
Oh BTW, one more thing! An I will soon explain more about the Wiring API in a Trailblazer Tales episode. 🍻 |
Hey @elShiaLabeouf feel free to hit me up directly on https://trailblazer.zulipchat.com to discuss ☝️ |
Oh, I see. I've come up with this minimalistic PR. Please take a look. I didn't realize the outputs were accessible from the operation class itself. |
That was quite a bit of overengineering before 😂 |
Any update on this? I think it would be nice to check easier for different end semantics. operation = Payment::Operation::Create.(provider: "bla-unknown")
if operation.success?
render "success"
elsif operation.semantic == :provider_invalid # or operation.semantic?(:provider_invalid)
render "provider_error"
else
render "error"
end |
We're putting this into the |
@eliten00b @elShiaLabeouf Here's a rough outlook of how I envision the interface: https://github.com/trailblazer/trailblazer-endpoint/blob/master/test/matcher_test.rb#L17 - it will look slightly less clumsy in a controller. Any comments here? 🍻 |
Does this mean any custom terminus is not consider a failure anymore? |
@eliten00b Interesting! A custom output has never been a "failure" per definition, that's why we gave it an attribute "semantic". It's up to the user to decide what "not_found" means. What makes you think that this is now different with the above example? |
True, I never read that a custom terminus is consider a failure. Most of our operation use the When I check From your code it reads that at least the From the initial code:
currently it would be:
|
@eliten00b Good point! Let me finalize my code over here and then we can discuss the API for |
Hello @apotonick and the Trailblazer team!
I think Adding outputs is a really powerful feature since it enables handling multiple outcomes during the operation run.
I also enjoy using
operation.success?
andoperation.failure?
methods that come in handy in controller actions routing.But when I'm using a custom output in an operation, to check which pipeline the operation went, I have to do the following:
I think it would be more intuitive and kinda elegant if instead of
operation.event.to_h[:semantic] == :provider_invalid
I could use a binary state methodoperation.provider_invalid?
I'd like to come up with a proposal to add such methods to a number of classes/objects like
#<Trailblazer::Activity::Railway::End::Success semantic=:success>
,#<Trailblazer::Activity::End semantic=:paypal>
etc..I have tested my changes locally and it works like this:
The changes
To achieve this I had to add bits of code to three gems:
success?
failure?
fail_fast?
pass_fast?
and<custom_output>?
toTrailblazer::Activity::End
:End::Success
,End::Failure
objects inTrailblazer::Activity::DSL::Linear::Normalizer::OutputTuples#register_additional_outputs
(which is called every time a new custom output is defined):success?
,failure?
and addedmethod_missing
for delegation inTrailblazer::Operation::Result
:after that I tested the code with the example above and got those result.
I understand that the code I propose to add might seem complicated, but on the other hand in return we get:
trailblazer-activity
.success?
andfailure?
intrailblazer-operation
.The code above can be added to the Trailblazer family step by step, PR by PR and it won't break a thing. I'm willing to create this series of PRs.
Looking forward to hearing your thoughts on my proposal!
The text was updated successfully, but these errors were encountered: