Created
March 3, 2022 06:23
-
-
Save percybolmer/7e8dfd08f3dc2df443a6e1885ab0310c to your computer and use it in GitHub Desktop.
Cadence execute childworkflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Preconfigure ChildWorkflow Options | |
orderWaiterCfg := workflow.ChildWorkflowOptions{ | |
ExecutionStartToCloseTimeout: time.Minute * 2, // Each Order can tops take 2 min | |
} | |
// Grab the Selector from the workflow Context, | |
selector := workflow.NewSelector(ctx) | |
// For ever running loop | |
for { | |
// Get the Signal used to identify an Event, we named our Order event into order | |
signalChan := workflow.GetSignalChannel(ctx, "order") | |
// We add a "Receiver" to the Selector, The receiver is a function that will trigger once a new Signal is recieved | |
selector.AddReceive(signalChan, func(c workflow.Channel, more bool) { | |
// Create the Order to marshal the Input into | |
var order Order | |
// Receive will read input data into the struct | |
c.Receive(ctx, &order) | |
// increment signal counter | |
signalCount++ | |
// Create ctx for Child flow | |
orderCtx := workflow.WithChildOptions(ctx, orderWaiterCfg) | |
// Trigger the child workflow | |
waiter := workflow.ExecuteChildWorkflow(orderCtx, workflowProcessOrder, order) | |
if err := waiter.Get(ctx, nil); err != nil { | |
workflow.GetLogger(ctx).Error("Order has failed.", zap.Error(err)) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment