-
Notifications
You must be signed in to change notification settings - Fork 225
Providing a mechanism to pass a list of Works in SequentialFlow #16
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
Comments
I have forked and pushed the changes here - |
Thank you for opening this issue. I can understand overloading the SequentialFlow sequentialFlow = SequentialFlow.Builder.aNewSequentialFlow()
.execute(work1, work2)
.execute(work3)
.then(work4)
... which does not make sense to me.
That's different. For a parallel flow, it does not make sense to have a method
LGTM. If you remove the overloading of the |
Thank you for your feedback !
The sole reason for wanting to have an additional
Currently the order of execution of the sequentialFlow is defined by the order in which it is being built. For example, I can build something like this and the flow will be executed in the order it is being built irrespective of the method -
We can plan to fix this pattern as well as a part of the step builder pattern fix. The suggestion is just to ease the building of the sequentialFlow by passing a list dynamically, instead of having to write the same code Let me know if you agree with this. |
@arunav-b #18 is now resolved. By using the step builder pattern, it is now impossible to write semantically incorrect workflow definitions. The builder will guide the user to call methods in the right order like: SequentialFlow sequentialFlow = SequentialFlow.Builder.aNewSequentialFlow()
.execute(work1)
.then(work2) // this is optional
.then(work3) // this is optional
.build(); We can now add overloaded SequentialFlow sequentialFlow = SequentialFlow.Builder.aNewSequentialFlow()
.execute(work1, work2)
.then(work3, work4) // this is optional
.build(); Feel free to open a PR if you want to contribute, otherwise let me know and I will introduce the changes. |
For an application supporting multiple complex workflows for different APIs with a considerable number of Works in each WorkFlow, it is kind of redundant to provide the individual Works/WorkFlows everytime for building a new WorkFlow. Everytime if they have to add or delete a worker from a WorkFlow, they have to make a change in the code where the workflow is being built. Ideally, I would want to abstract the building and execution of a particular type of WorkFlow from the multiple developers working on a large codebase and would just want them to write only the specific Work to support or enhance the Business process.
For example, all the Works part of a particular WorkFlow can be defined under a single package and at runtime just the package can be passed to a WorkFlow builder, which can internally create a List of Works under that particular package and pass it to the easy-flows SequentialFlow. With the current implementation however this is not possible as I have to use the builder pattern for building individual SequentialFlows by providing the Works/WorkFlows explicitly.
With a minor enhancement to the SequentialFLow Builder, we will be able to accomplish this.
Currently the execute() method accepts Work, but if we provide an overridden method of execute to accept List, then that will provide the flexibility to the users on how they want to use it -
public SequentialFlow.Builder execute(List works) {
this.works.addAll(works);
return this;
}
The developers can simply write their individual Works in a particular package and then an abstracted SequentialWorkFlowBuilder class can scan through all the Works in that particular package and create the list of Works at runtime. This list can be passed to the execute(List works). We may also consider about the then() method, which can also be overridden to accept List.
In this context I would like to highlight that, the ParallelFlow already has this option -
List works = workerList; //passed at runtime
Work[] workList = works.stream().toArray(Work[]::new);
ParallelFlow flow = aNewParallelFlow(Executors.newFixedThreadPool(2))
.execute(workList)
.build();
Please let me know your views on this.
Thanks,
Arunav
The text was updated successfully, but these errors were encountered: