Skip to content

Commit

Permalink
set WorkflowExecutionErrorWhenAlreadyStarted to true
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigozhou committed Feb 14, 2025
1 parent 55c1404 commit 1210104
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,11 @@ type (
// When WorkflowExecutionErrorWhenAlreadyStarted is true, Client.ExecuteWorkflow will return an error if the
// workflow id has already been used and WorkflowIDReusePolicy or WorkflowIDConflictPolicy would
// disallow a re-run. If it is set to false, rather than erroring a WorkflowRun instance representing
// the current or last run will be returned. However, when WithStartOperation is set, this field is ignored and
// the WorkflowIDConflictPolicy UseExisting must be used instead to prevent erroring.
// the current or last run will be returned. However, this field is ignored in the following cases:
// - when WithStartOperation is set;
// - in the Nexus WorkflowRunOperation.
// When this field is ignored, you must set WorkflowIDConflictPolicy to UseExisting to prevent
// erroring.
//
// Optional: defaults to false
WorkflowExecutionErrorWhenAlreadyStarted bool
Expand Down
7 changes: 7 additions & 0 deletions temporalnexus/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type WorkflowRunOperationOptions[I, O any] struct {
// The options returned must include a workflow ID that is deterministically generated from the input in order
// for the operation to be idempotent as the request to start the operation may be retried.
// TaskQueue is optional and defaults to the current worker's task queue.
// WorkflowExecutionErrorWhenAlreadyStarted is ignored and always set to true.
GetOptions func(context.Context, I, nexus.StartOperationOptions) (client.StartWorkflowOptions, error)
// Handler for starting a workflow with a different input than the operation. Mutually exclusive with Workflow
// and GetOptions.
Expand Down Expand Up @@ -401,6 +402,12 @@ func ExecuteUntypedWorkflow[R any](
internal.SetLinksOnStartWorkflowOptions(&startWorkflowOptions, links)
internal.SetOnConflictOptionsOnStartWorkflowOptions(&startWorkflowOptions)

// This makes sure that ExecuteWorkflow will respect the WorkflowIDConflictPolicy, ie., if the
// conflict policy is to fail (default value), then ExecuteWorkflow will return an error if the
// workflow already running. For Nexus, this ensures that operation has only started successfully
// when the callback has been attached to the workflow (new or existing running workflow).
startWorkflowOptions.WorkflowExecutionErrorWhenAlreadyStarted = true

run, err := nctx.Client.ExecuteWorkflow(ctx, startWorkflowOptions, workflowType, args...)
if err != nil {
return nil, err
Expand Down

0 comments on commit 1210104

Please sign in to comment.