Temporal Activity Retry Policy

Could you please help me understand how can we achieve the same in Golang?

retryPolicy := &temporal.RetryPolicy{
		InitialInterval:    time.Second,
		BackoffCoefficient: 2,
		MaximumInterval:    time.Minute,
		MaximumAttempts:    10,
	}
	options := workflow.ActivityOptions{
		StartToCloseTimeout: time.Minute * 5,
		RetryPolicy:         retryPolicy,
	}
	ctx = workflow.WithActivityOptions(ctx, options)

	logger.Info("starting workflow!")
	
	err := workflow.ExecuteActivity(
		ctx,
		Activity_1,
		configuration,
		workflow.GetInfo(ctx).WorkflowStartTime,
	).Get(
		ctx,
		nil,
	)
	if err != nil {
		return nil, err
	}

	err := workflow.ExecuteActivity(
		ctx,
		Activity_2,
		configuration,
		workflow.GetInfo(ctx).WorkflowStartTime,
	).Get(
		ctx,
		nil,
	)
	if err != nil {
		return nil, err
	}

	err := workflow.ExecuteActivity(
		ctx,
		Activity_3,
		configuration,
		workflow.GetInfo(ctx).WorkflowStartTime,
	).Get(
		ctx,
		nil,
	)
	if err != nil {
		return nil, err
	}

Here, the Activities named as Activity_1, Activity_2, and Activity_3 would be retried 10 times in case of failure, since we have configured it as

MaximumAttempts:    10,

I want to do something like, I don’t want Activity_3 to be retried at all. I just want it to run once, in case of failure.

Also, I don’t want to declare the retry policy for Activity_3 again.

How can I achieve the same?

Is there any way, I can pass some or any argument to the workflow.ExecuteActivty() method to avoid the retried completely?

Any pointers or suggestions would help thanks.

The way to achieve this is to define a different RetryPolicy (i.e., one which doesn’t allow any retries) that you’ll associate with the ExecuteActivity call for Activity_3.

Since the RetryPolicy is used to create the workflow.Context instance (ctx) passed into that ExecuteActivity call, this means that you’ll create one (which uses the original policy) when calling Activity_1 and Activity_2, and a different one when calling Activity_3.

I apologize that I don’t have a code sample readily available, but hopefully that explanation will help.