Question

I have a long running process with four steps. S1, S2, S3, S4. S2 and S3 are running sequential, S1 can run parallel to S2. S4 can run parallel to S1, S2 and S3.

Not all processes need to run through all steps. Some only need S2 and S3. Others maybe use S2 and S4.

Now could create one saga class and handle S1,S2,S3 and S4. Many If statements in message and timeout handlers. Next month someone needs to implement S5, running parallel to S3 and S4.

It would be possible to create one saga per possible process flow, but that's many duplicated code. Is it possible to create a class for each step and compose each different process flow by implementing the needed steps in different saga classes?

Should i build 4 saga's and control the process flow from an extern controller and only using the saga to perform the needed timeouts and persistance?

Was it helpful?

Solution

This sounds like a fairly classic Scatter/Gather pattern, which you can implement in one Saga.

At the beginning, you'll have some logic that determines which steps (all of which can run in parallel) need doing. You should send commands to have all those things done, and record in your saga data which steps you are awaiting responses from.

Each step happens as a message handler external to the saga and does a Bus.Reply() when complete.

As the reply messages come in, the Saga notes each step as it is completed, and when all steps are completed, you can take additional action to continue, likely publishing some sort of completion event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top