conductor
conductor copied to clipboard
[FEATURE]: Support system tasks other than the SubWorkflow task as parent of a Sub Workflow
Describe the Feature Request
I have been working on an custom system task that launches multiple SubWorkflows in a loop. However, I found there were a number of places with logic hardcoded to taskType that prevented this working.
There are hardcoded references to SUB_WORKFLOW in the following places methods:
-
WorkflowExecutorOps.executeSubworkflowTaskAndSyncDatacalled fromupdateParentWorkflowTask
@VisibleForTesting
void updateParentWorkflowTask(WorkflowModel subWorkflow) {
TaskModel subWorkflowTask =
executionDAOFacade.getTaskModel(subWorkflow.getParentWorkflowTaskId());
executeSubworkflowTaskAndSyncData(subWorkflow, subWorkflowTask);
executionDAOFacade.updateTask(subWorkflowTask);
}
private void executeSubworkflowTaskAndSyncData(
WorkflowModel subWorkflow, TaskModel subWorkflowTask) {
WorkflowSystemTask subWorkflowSystemTask =
systemTaskRegistry.get(TaskType.TASK_TYPE_SUB_WORKFLOW);
subWorkflowSystemTask.execute(subWorkflow, subWorkflowTask, this);
}
-
WorkflowExecutorOps.findChangedSubWorkflowTask
- note the initial filtering here might be a bug assuming DYNAMIC_TASK could also run a SubWorkflow task
if (workflowDef.containsType(TaskType.TASK_TYPE_SUB_WORKFLOW)
|| workflow.getWorkflowDefinition()
.containsType(TaskType.TASK_TYPE_FORK_JOIN_DYNAMIC)) {
return workflow.getTasks().stream()
.filter(
t ->
t.getTaskType().equals(TaskType.TASK_TYPE_SUB_WORKFLOW)
&& t.isSubworkflowChanged()
&& !t.isRetried())
.findFirst();
}
-
WorkflowExecutorOps.rerunWF(line 1669 & 1772) -
WorkflowExecutorOps.findLastFailedSubWorkflowIfAny(line 413) -
WorkflowRepairService.verifyAndRepairTask(line 154)
Describe Preferred Solution
- Change the
WorkflowExecutorOps.executeSubworkflowTaskAndSyncDatato passsubWorkflowTask.getTaskType()to thesystemTaskRegistry
private void executeSubworkflowTaskAndSyncData(
WorkflowModel subWorkflow, TaskModel subWorkflowTask) {
WorkflowSystemTask subWorkflowSystemTask =
systemTaskRegistry.get(subWorkflowTask.getTaskType()); // replace hard coding here
subWorkflowSystemTask.execute(subWorkflow, subWorkflowTask, this);
}
- And the following method to
WorkflowSystemTaskinterface and override to return true inSubWorkflowclass:
public boolean isSubWorkflowParent() { return false; }
Add additional method to SystemTaskRegistry
public boolean isSubWorkflowParent(String taskType) {
return get(taskType).isSubWorkflowParent();
}
- Replace logic that explicitly checks for hardcoding with checks on the SystemRegistry
`` systemTaskRegistry.isSubWorkflowParent(t.getTaskType())
## Describe Alternatives
I am not aware of other viable options, as the task type still needs to be unique