interactor icon indicating copy to clipboard operation
interactor copied to clipboard

Add an :allow_failure option to the organize method to swallow failure and continue execution

Open laserlemon opened this issue 8 years ago • 6 comments

This probably shouldn't hijack context.fail! but instead should override the organizer's handling of an individual interactor's failure.

laserlemon avatar Mar 24 '17 18:03 laserlemon

How would it play with rollbacking of a context? Currently it's launched automatically on failure.

I thought about passing a copy of a context to an organized interactor. It will complicate things significantly (need to contexts merging will arise) but allows us to isolate failures.

hedgesky avatar Mar 25 '17 10:03 hedgesky

If :allow_failure is set to true for one of the organized interactors, I'm imagining that if that interactor fails, the organizer will recognize that failure and revert the context to a success before moving on. No rollbacks expected. I'd love to hear other suggestions if that doesn't feel right.

laserlemon avatar Mar 26 '17 13:03 laserlemon

Hey Steve, your gem is pretty central in our app -- thanks so much! 🥇

In our use-case, we don't foresee a need to call the rollbacks on previously run interactors.

We currently have some actions that call interactors in succession precisely because they are irreversible/doesn't make sense to reverse. Kind of like: organize: BuySomething, SubscribeEmail if SubscribeEmail failed, well, we don't really care about it vs BuySomething. Which is why we're handling them in succession vs putting it in an organizer(which with :allow_failure would now let us do I think).

mikebernardez avatar Mar 31 '17 00:03 mikebernardez

@mikebernardez Great, thank you for the feedback!

laserlemon avatar Mar 31 '17 12:03 laserlemon

Hey @laserlemon, thanks for your work on this gem.

Another use-case for this feature. If you have organize DoSomething, NotifyIfSomethingHappenedOrNot. In that case you might want the context to contain that it failed in the previous interactor. So maybe the context becomes a success but we have context.previous_state which might be fail or success.

fluke avatar Jun 05 '18 11:06 fluke

I would love to be able to log and perform other actions on failure, but right now the fail hijacks and ends execution. Thoughts?

thekevin-cisco avatar May 23 '19 18:05 thekevin-cisco