Skip to main content

How to set StartWorkflowOptions in Go

Create an instance of StartWorkflowOptions from the go.temporal.io/sdk/client package, and pass the instance to the ExecuteWorkflow call.

The following fields are available:

FieldRequiredTypeExample
IDNostring👀
TaskQueueYesstring👀
WorkflowExecutionTimeoutNotime.Duration👀
WorkflowRunTimeoutNotime.Duration👀
WorkflowTaskTimeoutNotime.Duration👀
WorkflowIDReusePolicyNoWorkflowIdReusePolicy👀
WorkflowExecutionErrorWhenAlreadyStartedNobool👀
RetryPolicyNoRetryPolicy👀
CronScheduleNostring👀
MemoNomap[string]interface{}👀
SearchAttributesNomap[string]interface{}👀

ID#

workflowOptions := client.StartWorkflowOptions{  ID: "Your-Custom-Workflow-Id",  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

TaskQueue#

workflowOptions := client.StartWorkflowOptions{  TaskQueue: "your-task-queue",}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

WorkflowExecutionTimeout#

workflowOptions := client.StartWorkflowOptions{  WorkflowExecutionTimeout: time.Hour * 10,  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

WorkflowRunTimeout#

workflowOptions := client.StartWorkflowOptions{  WorkflowRunTimeout: time.Hour * 10,  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

WorkflowTaskTimeout#

workflowOptions := client.StartWorkflowOptions{  WorkflowTaskTimeout: time.Second * 10,  //...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

WorkflowIDReusePolicy#

Set a value from the go.temporal.io/api/enums/v1 package.

workflowOptions := client.StartWorkflowOptions{  WorkflowIdReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE,  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

WorkflowExecutionErrorWhenAlreadyStarted#

workflowOptions := client.StartWorkflowOptions{  WorkflowExecutionErrorWhenAlreadyStarted: false,  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

RetryPolicy#

Create an instance of a RetryPolicy from the go.temporal.io/sdk/temporal package and provide it as the value to the RetryPolicy field of the instance of StartWorkflowOptions.

retrypolicy := &temporal.RetryPolicy{  InitialInterval:    time.Second,  BackoffCoefficient: 2.0,  MaximumInterval:    time.Second * 100,}workflowOptions := client.StartWorkflowOptions{  RetryPolicy: retrypolicy,  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

CronSchedule#

workflowOptions := client.StartWorkflowOptions{  CronSchedule: "15 8 * * *",  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

Memo#

workflowOptions := client.StartWorkflowOptions{  Memo: map[string]interface{}{    "description": "Test search attributes workflow",  },  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}

SearchAttributes#

Search Attribute types are defined in the Elasticsearch Index Schema. These are the corresponding Search Attribute value types in Go:

  • Keyword = string
  • Int = int64
  • Double = float64
  • Bool = bool
  • Datetime = time.Time
  • String = string
searchAttributes := map[string]interface{}{  "CustomIntField": 1,  "MiscData": "yellow",}workflowOptions := client.StartWorkflowOptions{  SearchAttributes: searchAttributes,  // ...}workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)if err != nil {  // ...}