You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi first let me thank you for this code, seems like this is exactly what I was looking for!
I just wanted to implement some kind of dependency for the individual stages of a pipeline with some extensive try catch error handling but then stumbled across the InterruptibleProcessor.php and I was wondering if there might be a better way to do that, but I am not sure how to use the $check callable - do I understand the code right that it allows for one $check callable for each pipeline and not for one $check for each $stage?
I just want to let pipelines stop or skip or trigger a different pipeline based on the results of one stage.
Also I am wondering: what would be the best way to build fallback chains? Something like "if stage_x fails, try again with $stage_y" or "if $stage_x produces result x skip to stage_z"?
I am just experimenting to learn if it might make sense to transform an existing large if-then-else monstrosity into a few pipelines and do not immediately see how to implement such kind of fallbacks. Also of course I would like to avoid writing lots of try catch error handling code - the result should be less code than the if-then-else horror I would like to replace... :)
If you could find the time for providing a little example how you would implement such a thing, it would be a great help! Thanks for your attention!
The text was updated successfully, but these errors were encountered:
// This is one way to check for errors and skip to the end of a pipeline during processing . . .
// Create the Pipeline
$pipeline = (new Pipeline(
// Set the processor to InterruptibleProcessor (instead of FingersCrossed)
new InterruptibleProcessor(
// Create a class GetOkay->__invoke() that calls $payload->getOkay()
// Pass GetOkay into InterruptibleProcessor so it knows where to check.
new GetOkay
)
))
// Create a Payload class with setOkay(), getOkay(), and a private property $okay
// Note: Line 25 InterruptibleProcessor is " if (true !== $check($payload)) { "
->pipe(new CreatePayload)
// Create a CheckBeforeFirstAction class to update $payload->setOkay() as needed.
// This class can check to make sure all requirements are OK to run FirstAction.
// Tip: Every class in the pipeline should (modify and) return the $payload object.
->pipe(new CheckBeforeFirstAction)
// CheckBeforeFirstAction(Payload $payload) returns the $payload object.
// The InterruptibleProcessor will check for an error using GetOkay->_invoke()
// If $payload->okay is still set to true the FirstAction will run
->pipe(new FirstAction)
// Create a CheckBeforeSecondAction class to $payload->setOkay() as needed.
->pipe(new CheckBeforeSecondAction)
// Set $payload->setOkay('false') inside CheckBeforeSecondAction as a test.
// The InterruptibleProcessor will check for an error using GetOkay->_invoke()
// The SecondAction will NOT be run since $payload->okay = false.
->pipe(new SecondAction);
// The $payload will be returned from InterruptibleProcessor.
// wowcut: Set a property in the $payload to specify which stages should run.
// I don't think you will reduce the if-then-else, but you can hide them in Check classes
Hi first let me thank you for this code, seems like this is exactly what I was looking for!
I just wanted to implement some kind of dependency for the individual stages of a pipeline with some extensive try catch error handling but then stumbled across the
InterruptibleProcessor.php
and I was wondering if there might be a better way to do that, but I am not sure how to use the $check callable - do I understand the code right that it allows for one $check callable for each pipeline and not for one $check for each $stage?I just want to let pipelines stop or skip or trigger a different pipeline based on the results of one stage.
Also I am wondering: what would be the best way to build fallback chains? Something like "if stage_x fails, try again with $stage_y" or "if $stage_x produces result x skip to stage_z"?
I am just experimenting to learn if it might make sense to transform an existing large if-then-else monstrosity into a few pipelines and do not immediately see how to implement such kind of fallbacks. Also of course I would like to avoid writing lots of try catch error handling code - the result should be less code than the if-then-else horror I would like to replace... :)
If you could find the time for providing a little example how you would implement such a thing, it would be a great help! Thanks for your attention!
The text was updated successfully, but these errors were encountered: