From 15c05dae8232d820e015acbe5a66ea971c1a5cab Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Fri, 25 Oct 2024 07:25:57 -0400 Subject: [PATCH] Use UpdateWorkflow for Update-With-Start --- early-return/starter/main.go | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/early-return/starter/main.go b/early-return/starter/main.go index ad54eb5d..58f95651 100644 --- a/early-return/starter/main.go +++ b/early-return/starter/main.go @@ -20,31 +20,23 @@ func main() { ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - updateOperation := client.NewUpdateWithStartWorkflowOperation( - client.UpdateWorkflowOptions{ - UpdateName: earlyreturn.UpdateName, - WaitForStage: client.WorkflowUpdateStageCompleted, - }) - tx := earlyreturn.Transaction{ID: uuid.New(), SourceAccount: "Bob", TargetAccount: "Alice", Amount: 100} - workflowOptions := client.StartWorkflowOptions{ - ID: "early-return-workflow-ID-" + tx.ID, - TaskQueue: earlyreturn.TaskQueueName, - WithStartOperation: updateOperation, - } - we, err := c.ExecuteWorkflow(ctxWithTimeout, workflowOptions, earlyreturn.Workflow, tx) - if err != nil { - log.Fatalln("Error executing workflow:", err) - } - - log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID()) - updateHandle, err := updateOperation.Get(ctxWithTimeout) + updateHandle, err := c.UpdateWorkflow(ctxWithTimeout, client.UpdateWorkflowOptions{ + UpdateName: earlyreturn.UpdateName, + WaitForStage: client.WorkflowUpdateStageCompleted, + StartWorkflow: earlyreturn.Workflow, + StartWorkflowArgs: []any{tx}, + StartWorkflowOptions: &client.StartWorkflowOptions{ + ID: "early-return-workflow-ID-" + tx.ID, + TaskQueue: earlyreturn.TaskQueueName, + }, + }) if err != nil { - log.Fatalln("Error obtaining update handle:", err) + log.Fatalln("Error starting workflow and waiting for update result:", err) } - - err = updateHandle.Get(ctxWithTimeout, nil) + var earlyReturnResult any + err = updateHandle.Get(ctxWithTimeout, &earlyReturnResult) if err != nil { // The workflow will continue running, cancelling the transaction.