Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to remove the RetryPolicy from the workflow context without overriding the other existing ActivityOptions in it #1418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1839,9 +1839,9 @@ func WithWaitForCancellation(ctx Context, wait bool) Context {
}

// WithRetryPolicy adds retry policy to the copy of the context
func WithRetryPolicy(ctx Context, retryPolicy RetryPolicy) Context {
func WithRetryPolicy(ctx Context, retryPolicy *RetryPolicy) Context {
ctx1 := setActivityParametersIfNotExist(ctx)
getActivityOptions(ctx1).RetryPolicy = convertRetryPolicy(&retryPolicy)
getActivityOptions(ctx1).RetryPolicy = convertRetryPolicy(retryPolicy)
return ctx1
}

Expand Down
7 changes: 7 additions & 0 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ func (ts *IntegrationTestSuite) TestActivityRetryOptionsChange() {
ts.EqualValues(expected, ts.activities.invoked())
}

func (ts *IntegrationTestSuite) TestActivityRetryOptionsRemove() {
var expected []string
err := ts.executeWorkflow("test-activity-retry-options-remove", ts.workflows.ActivityRetryOptionsRemove, &expected)
ts.NoError(err)
ts.EqualValues(expected, ts.activities.invoked())
}

func (ts *IntegrationTestSuite) TestActivityRetryOnStartToCloseTimeout() {
var expected []string
err := ts.executeWorkflow(
Expand Down
12 changes: 12 additions & 0 deletions test/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ func (w *Workflows) ActivityRetryOptionsChange(ctx workflow.Context) ([]string,
return []string{"fail", "fail"}, nil
}

func (w *Workflows) ActivityRetryOptionsRemove(ctx workflow.Context) ([]string, error) {
opts := w.defaultActivityOptionsWithRetry()
ctx = workflow.WithActivityOptions(ctx, opts)
ctx = workflow.WithRetryPolicy(ctx, nil)
err := workflow.ExecuteActivity(ctx, "Fail").Get(ctx, nil)
if err == nil {
return nil, fmt.Errorf("expected activity to fail but succeeded")
}
return []string{"fail"}, nil
}

func (w *Workflows) ActivityRetryOnTimeout(ctx workflow.Context, timeoutType shared.TimeoutType) ([]string, error) {
opts := w.defaultActivityOptionsWithRetry()
switch timeoutType {
Expand Down Expand Up @@ -625,6 +636,7 @@ func (w *Workflows) register(worker worker.Worker) {
worker.RegisterWorkflow(w.ActivityAutoHeartbeat)
worker.RegisterWorkflow(w.ActivityRetryOnTimeout)
worker.RegisterWorkflow(w.ActivityRetryOptionsChange)
worker.RegisterWorkflow(w.ActivityRetryOptionsRemove)
worker.RegisterWorkflow(w.ContinueAsNew)
worker.RegisterWorkflow(w.ContinueAsNewWithOptions)
worker.RegisterWorkflow(w.IDReusePolicy)
Expand Down
2 changes: 1 addition & 1 deletion workflow/activity_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ func WithWaitForCancellation(ctx Context, wait bool) Context {
// WithRetryPolicy makes a copy of the current context and update
// the RetryPolicy field in its activity options. An empty activity
// options will be created if it does not exist in the original context.
func WithRetryPolicy(ctx Context, retryPolicy RetryPolicy) Context {
func WithRetryPolicy(ctx Context, retryPolicy *RetryPolicy) Context {
return internal.WithRetryPolicy(ctx, retryPolicy)
}