added experimental support of Flexible Processes#1040
added experimental support of Flexible Processes#1040treblereel wants to merge 4 commits intoserverlessworkflow:mainfrom
Conversation
| for (Activity activity : flexibleProcess.getActivities()) { | ||
| TaskExecutorBuilder<?> builder = | ||
| factory.getTaskExecutor(position, activity.getTask(), definition); | ||
| TaskExecutor<?> executor = builder.build(); | ||
| executors.put(activity, executor); | ||
| } |
There was a problem hiding this comment.
This should be done on the builder classs, not as part of every execution.
Take a look to https://github.com/serverlessworkflow/sdk-java/blob/main/impl/core/src/main/java/io/serverlessworkflow/impl/executors/CallFunctionExecutorBuilder.java
| } catch (Exception e) { | ||
| throw new RuntimeException("Error executing activity: " + activity.getName(), e); | ||
| } |
There was a problem hiding this comment.
We shoulds not catch exception generically
| executor | ||
| .apply(workflowContext, parentContext, input) | ||
| .join(); // blocking, because we run flexible process one by one |
There was a problem hiding this comment.
If we want to run one executor after another, rather that invoking join, we should chain completable future using thenAccept.
| exit = flexibleProcess.getExitCondition().test(input); | ||
| if (exit) { | ||
| break; | ||
| } | ||
| } | ||
| counter--; | ||
| if (counter <= 0) { | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
I think the loop termination condition should be revised, why counter is not part of the while?
| .filter(activity -> activity.getKey().isRepeatable() || !activity.getKey().isExecuted()) | ||
| .filter(e -> e.getKey().getEntryCondition().test(input)) |
There was a problem hiding this comment.
These two filters can be merge into one
| return this; | ||
| } | ||
|
|
||
| public FlexibleProcessBuilder maxAttempts(Integer maxAttempts) { |
There was a problem hiding this comment.
Why not using a int parameter, so you do not have to care about null?
| flexibleProcess.exitCondition = | ||
| Objects.requireNonNull(this.exitCondition, "Exit condition must be provided"); | ||
| flexibleProcess.activities = | ||
| Objects.requireNonNull(this.activities, "Activities must be provided"); |
There was a problem hiding this comment.
If exitCondition and activities are mandatory, then, they should be provided when creating the builder rather than using with methods.
Builder pattern should be used when you have few mandatory parameter and a lot of optionals (or defaults)
Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com>
6132d3a to
fad4d43
Compare
Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com>
fad4d43 to
45a0397
Compare
| Map<Activity, TaskExecutor<?>> executors = new HashMap<>(); | ||
| for (Activity activity : flexibleProcess.getActivities()) { | ||
| TaskExecutorBuilder<?> builder = | ||
| factory.getTaskExecutor(position, activity.getTask(), definition); | ||
| TaskExecutor<?> executor = builder.build(); | ||
| executors.put(activity, executor); |
There was a problem hiding this comment.
Still unclear to me why creating the executor Map has to be deferred till execution time
|
|
||
| public Activity build() { | ||
| return new Activity( | ||
| Objects.requireNonNull(task, "Task must be provided"), |
There was a problem hiding this comment.
If task and entry are required (because there is not valid default), they should be parameters of the method that create the builder
Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com>
| this.executors = | ||
| executors.entrySet().stream() | ||
| .collect(Collectors.toMap(entry -> entry.getKey().copy(), Map.Entry::getValue)); |
There was a problem hiding this comment.
Why do the executor map has to be cloned?
There was a problem hiding this comment.
Activity keeps track of its own execution state, so we need to create a new instance when used, in other words, an Activity is a prototype
Signed-off-by: Dmitrii Tikhomirov <chani.liet@gmail.com>
Many thanks for submitting your Pull Request ❤️!
What this PR does / why we need it:
Special notes for reviewers:
Additional information (if needed):