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:

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

ID

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

TaskQueue

  • Type: string
  • Default: None, this is a required field to be set by the developer
workflowOptions := client.StartWorkflowOptions{
TaskQueue: "your-task-queue",
}
workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)
if err != nil {
// ...
}

WorkflowExecutionTimeout

  • Type: time.Duration
  • Default: 10 years
workflowOptions := client.StartWorkflowOptions{
WorkflowExecutionTimeout: time.Hours * 24 * 365 * 10,
// ...
}
workflowRun, err := c.ExecuteWorkflow(context.Background(), workflowOptions, YourWorkflowDefinition)
if err != nil {
// ...
}

WorkflowRunTimeout

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

WorkflowTaskTimeout

  • Type: time.Duration
  • Default: time.Seconds * 10
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

  • Type: bool
  • Default: false
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

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

Sample

Memo

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

SearchAttributes

  • Type: map[string]interface{}
  • Default: Empty.

These are the corresponding Search Attribute value types in Go:

  • Keyword = string
  • Int = int64
  • Double = float64
  • Bool = bool
  • Datetime = time.Time
  • Text = 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 {
// ...
}

Get notified of updates