Skip to content

Commit

Permalink
Use UpdateWorkflow for Update-With-Start
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Oct 25, 2024
1 parent 41d3b0e commit 15c05da
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions early-return/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check failure on line 28 in early-return/starter/main.go

View workflow job for this annotation

GitHub Actions / build-and-test

unknown field StartWorkflow in struct literal of type "go.temporal.io/sdk/internal".UpdateWorkflowOptions
StartWorkflowArgs: []any{tx},

Check failure on line 29 in early-return/starter/main.go

View workflow job for this annotation

GitHub Actions / build-and-test

unknown field StartWorkflowArgs in struct literal of type "go.temporal.io/sdk/internal".UpdateWorkflowOptions
StartWorkflowOptions: &client.StartWorkflowOptions{

Check failure on line 30 in early-return/starter/main.go

View workflow job for this annotation

GitHub Actions / build-and-test

unknown field StartWorkflowOptions in struct literal of type "go.temporal.io/sdk/internal".UpdateWorkflowOptions (compile)
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.

Expand Down

0 comments on commit 15c05da

Please sign in to comment.