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.

FieldRequiredTypeExample
ActivityIDNostring👀
TaskQueueNameYesstring👀
ScheduleToCloseTimeoutYes (or StartToCloseTimeout)time.Duration👀
ScheduleToStartTimeoutNotime.Duration👀
StartToCloseTimeoutYes (or ScheduleToCloseTimeout)time.Duration👀
HeartbeatTimeoutNotime.Duration👀
WaitForCancellationNobool👀
OriginalTaskQueueNameNostring👀
RetryPolicyNoRetryPolicy👀

ActivityID#

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#

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#

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#

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#

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.

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#

Activity Executions have a default Retry Policy. Providing one here is a customization, and overwrites the default.

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 {  // ...}