Skip to main content

How to set ActivityOptions in Go

Create an instance of ActivityOptions from the go.temporal.io/sdk/workflow package and use WithActivityOptions() to apply it to the instance of workflow.Context.

The instance of workflow.Context is then passed to the ExecuteActivity() call.

FieldRequiredType
ActivityIDNostring
TaskQueueNameNostring
ScheduleToCloseTimeoutYes (or StartToCloseTimeout)time.Duration
ScheduleToStartTimeoutNotime.Duration
StartToCloseTimeoutYes (or ScheduleToCloseTimeout)time.Duration
HeartbeatTimeoutNotime.Duration
WaitForCancellationNobool
OriginalTaskQueueNameNostring
RetryPolicyNoRetryPolicy

ActivityID#

  • Type: string
  • Default: None
activityoptions := workflow.ActivityOptions{  ActivityID: "your-activity-id",}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

TaskQueueName#

  • Type: string
  • Default: Inherits the TaskQueue name from the Workflow.
activityoptions := workflow.ActivityOptions{  TaskQueueName: "your-task-queue-name",}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

ScheduleToCloseTimeout#

This or ScheduleToStart must be set.

  • Type: time.Duration
  • Default: โˆž (infinity - no limit)
activityoptions := workflow.ActivityOptions{  ScheduleToCloseTimeout: 10 * time.Second,}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

ScheduleToStartTimeout#

This or ScheduleToClose must be set.

  • Type: time.Duration
  • Default: โˆž (infinity - no limit)
activityoptions := workflow.ActivityOptions{  ScheduleToStartTimeout: 10 * time.Second,}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

StartToCloseTimeout#

  • Type: time.Duration
  • Default: Same as the ScheduleToCloseTimeout
activityoptions := workflow.ActivityOptions{  StartToCloseTimeout: 10 * time.Second,}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

HeartbeatTimeout#

activityoptions := workflow.ActivityOptions{  HeartbeatTimeout: 10 * time.Second,}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

WaitForCancellation#

If true the Activity Execution will finish executing should there be a Cancellation request.

  • Type: bool
  • Default: false
activityoptions := workflow.ActivityOptions{  WaitForCancellation: false,}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

OriginalTaskQueueName#

activityoptions := workflow.ActivityOptions{  OriginalTaskQueueName: "your-original-task-queue-name",}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

RetryPolicy#

retrypolicy := &temporal.RetryPolicy{  InitialInterval:    time.Second,  BackoffCoefficient: 2.0,  MaximumInterval:    time.Second * 100, // 100 * InitialInterval  MaximumAttempts: 0, // Unlimited  NonRetryableErrorTypes: []string, // empty}

Providing a Retry Policy here is a customization, and overwrites individual Field defaults.

retrypolicy := &temporal.RetryPolicy{  InitialInterval:    time.Second,  BackoffCoefficient: 2.0,  MaximumInterval:    time.Second * 100,}
activityoptions := workflow.ActivityOptions{  RetryPolicy: retrypolicy,}ctx = workflow.WithActivityOptions(ctx, activityoptions)var yourActivityResult YourActivityResulterr = workflow.ExecuteActivity(ctx, YourActivityDefinition, yourActivityParam).Get(ctx, &yourActivityResult)if err != nil {  // ...}

Get notified of updates