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

New Update-With-Start API #1731

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

New Update-With-Start API #1731

wants to merge 12 commits into from

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Nov 28, 2024

New Update-With-Start API.

  • Instead of using ExecuteWorkflow, update-with-start is invoked via a new method UpdateWithStartWorkflow on Client which returns an UpdateHandle
  • The method receives a WithStartWorkflowOperation struct which defines the start operation, and exposes a method to obtain the workflow run:

The snippet below is from the accompanying sample: temporalio/samples-go#370:

tx := earlyreturn.Transaction{ID: uuid.New(), SourceAccount: "Bob", TargetAccount: "Alice", Amount: 100}

startWorkflowOp := c.NewWithStartWorkflowOperation(client.StartWorkflowOptions{
	ID:                       "early-return-workflow-ID-" + tx.ID,
	WorkflowIDConflictPolicy: enumspb.WORKFLOW_ID_CONFLICT_POLICY_FAIL,
	TaskQueue:                earlyreturn.TaskQueueName,
}, earlyreturn.Workflow, tx)

updateHandle, err := c.UpdateWithStartWorkflow(ctxWithTimeout, client.UpdateWithStartWorkflowOptions{
	UpdateOptions: client.UpdateWorkflowOptions{
		UpdateName:   earlyreturn.UpdateName,
		WaitForStage: client.WorkflowUpdateStageCompleted,
	},
	StartOperation: startWorkflowOp,
})
if err != nil {
	log.Fatalln("Error issuing update-with-start:", err)
}
var earlyReturnResult any
err = updateHandle.Get(ctxWithTimeout, &earlyReturnResult)
if err != nil {
	// The workflow will continue running, cancelling the transaction.

	// NOTE: If the error is retryable, a retry attempt must use a unique workflow ID.
	log.Fatalln("Error obtaining update result:", err)
}

workflowRun, err := startWorkflowOp.Get(ctxWithTimeout)

client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
client/client.go Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants