Skip to content

Commit

Permalink
Demonstates a bug with calling the same child workflow twice from the…
Browse files Browse the repository at this point in the history
… same workflow
  • Loading branch information
mfateev committed Jul 3, 2024
1 parent 3496ec0 commit ab0b67a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions child-workflow/child_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package child_workflow

import (
"go.temporal.io/sdk/workflow"
"time"
)

// @@@SNIPSTART samples-go-child-workflow-example-child-workflow-definition
// SampleChildWorkflow is a Workflow Definition
func SampleChildWorkflow(ctx workflow.Context, name string) (string, error) {
if name == "World" {
workflow.Sleep(ctx, time.Hour)
}
logger := workflow.GetLogger(ctx)
greeting := "Hello " + name + "!"
logger.Info("Child workflow execution: " + greeting)
Expand Down
12 changes: 10 additions & 2 deletions child-workflow/parent_workflow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package child_workflow

import (
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/sdk/workflow"
)

Expand All @@ -13,12 +14,19 @@ func SampleParentWorkflow(ctx workflow.Context) (string, error) {
logger := workflow.GetLogger(ctx)

cwo := workflow.ChildWorkflowOptions{
WorkflowID: "ABC-SIMPLE-CHILD-WORKFLOW-ID",
WorkflowID: "ABC-SIMPLE-CHILD-WORKFLOW-ID",
WorkflowIDReusePolicy: enumspb.WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING,
}
ctx = workflow.WithChildOptions(ctx, cwo)

var result string
err := workflow.ExecuteChildWorkflow(ctx, SampleChildWorkflow, "World").Get(ctx, &result)
err := workflow.ExecuteChildWorkflow(ctx, SampleChildWorkflow, "World").GetChildWorkflowExecution().Get(ctx, nil)
if err != nil {
logger.Error("Parent execution received child execution failure.", "Error", err)
return "", err
}

err = workflow.ExecuteChildWorkflow(ctx, SampleChildWorkflow, "Foo").Get(ctx, &result)
if err != nil {
logger.Error("Parent execution received child execution failure.", "Error", err)
return "", err
Expand Down

0 comments on commit ab0b67a

Please sign in to comment.