Skip to content
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

NewForkTaskWithJoin(taskRefName string, join *JoinTask, forkedTask ...[]TaskInterface) #124

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion internal/testdata/kitchensink.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ func NewKitchenSinkWorkflow(executor *executor.WorkflowExecutor) *workflow.Condu
workflow.NewSimpleTask("simple_task", "simple_task_5"),
},
)
join := workflow.NewJoinTask("new_join_ref", "simple_task_fork_ref2", "simple_task_fork_ref4")
c4lm marked this conversation as resolved.
Show resolved Hide resolved
join.InputMap(map[string]interface{}{
"param1": "value",
})
forkWithJoin := workflow.NewForkTaskWithJoin("fork_with_join_fork_ref", join,
[]workflow.TaskInterface{
workflow.NewSimpleTask("simple_task", "simple_task_fork_ref1"),
workflow.NewSimpleTask("simple_task", "simple_task_fork_ref2"),
}, []workflow.TaskInterface{
workflow.NewSimpleTask("simple_task", "simple_task_fork_ref3"),
workflow.NewSimpleTask("simple_task", "simple_task_fork_ref4"),
})
dynamicFork := workflow.NewDynamicForkTask(
"dynamic_fork",
workflow.NewSimpleTask("dynamic_fork_prep", "dynamic_fork_prep"),
Expand Down Expand Up @@ -90,7 +102,8 @@ func NewKitchenSinkWorkflow(executor *executor.WorkflowExecutor) *workflow.Condu
Add(setVariable).
Add(subWorkflow).
Add(dynamicFork).
Add(fork)
Add(fork).
Add(forkWithJoin)

return workflow
}
Expand Down
21 changes: 20 additions & 1 deletion sdk/workflow/fork_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
type ForkTask struct {
Task
forkedTasks [][]TaskInterface
join *JoinTask
}

//NewForkTask creates a new fork task that executes the given tasks in parallel
Expand Down Expand Up @@ -57,6 +58,21 @@ func NewForkTask(taskRefName string, forkedTask ...[]TaskInterface) *ForkTask {
}
}

func NewForkTaskWithJoin(taskRefName string, join *JoinTask, forkedTask ...[]TaskInterface) *ForkTask {
return &ForkTask{
Task: Task{
name: taskRefName,
taskReferenceName: taskRefName,
description: "",
taskType: FORK_JOIN,
optional: false,
inputParameters: map[string]interface{}{},
},
forkedTasks: forkedTask,
join: join,
}
}

func (task *ForkTask) toWorkflowTask() []model.WorkflowTask {
forkWorkflowTask := task.Task.toWorkflowTask()[0]
forkWorkflowTask.ForkTasks = make([][]model.WorkflowTask, len(task.forkedTasks))
Expand All @@ -73,7 +89,10 @@ func (task *ForkTask) toWorkflowTask() []model.WorkflowTask {
}

func (task *ForkTask) getJoinTask() model.WorkflowTask {
join := NewJoinTask(task.taskReferenceName + "_join")
join := task.join
if join == nil {
join = NewJoinTask(task.taskReferenceName + "_join")
}
return (join.toWorkflowTask())[0]
}

Expand Down