uber-go / cadence-client

Framework for authoring workflows and activities running on top of the Cadence orchestration engine.

Home Page:https://cadenceworkflow.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support NewCustomError that doesn't always retry

peaaceChoi opened this issue · comments

Is your feature request related to a problem? Please describe.

NonRetriableErrorReasons are supposed to cadence errors in all cases where retry is not required. However, Activity has many conditions that do not need to be retried.
If validation for input fails as in the example below, there is no need to retry. This is because the same error is repeated.

RetryPolicy: &cadence.RetryPolicy{
			InitialInterval:          time.Second,
			BackoffCoefficient:       2.0,
			MaximumInterval:          time.Minute,
			ExpirationInterval:       time.Minute * 10,
			NonRetriableErrorReasons: []string{"ErrInvalidInput01",
			"ErrInvalidInput02",
			"ErrInvalidInput03",...},
		},

The problem is, if there is a large number of errors such as input validation, the NonRetriableErrorReasons must be described in all retry policy.

Proposed Solution

It can be solved in various ways, but I think it will be the simplest to add the noRetry related function to the newCustomError of the cadence client.
the user is not required to use Non Retriable Error Reasons if can identify specific errors by using the prefix of the new custom errors as shown below.

func NewCustomErrorWithNoRetry(reason string, details ...interface{}) *CustomError {
	return internal.NewCustomError("cadenceInternal:NoRetry:"+reason, details...)
}

Justly, need to modify the decision codes below.

cadence
https://github.com/uber/cadence/blob/7bd91051360214181464b87325615631a1712bb7/service/history/execution/retry.go#L83-L87

cadence client

for _, er := range p.NonRetriableErrorReasons {
if er == errReason {
return noRetryBackoff
}
}