diff --git a/activity/activity.go b/activity/activity.go index 093f23450..27b402ee3 100644 --- a/activity/activity.go +++ b/activity/activity.go @@ -42,7 +42,9 @@ type ( // RegisterOptions consists of options for registering an activity RegisterOptions = internal.RegisterActivityOptions - ActivityExtra = internal.ActivityExtra + // ExtraInformation is an additional data which should be sent to the server to influence its decision + // about the next retry + ExtraInformation = internal.ActivityExtraInformation ) // ErrResultPending is returned from activity's implementation to indicate the activity is not completed when @@ -112,6 +114,8 @@ func IsActivity(ctx context.Context) bool { return internal.IsActivity(ctx) } -func ExtraInformation() ActivityExtra { - return internal.NewActivityExtra() +// NewExtraInformation initialize structure to provide ExtraInformation to the server from the activity +// use WithXXX methods available for ExtraInformation instance to add your data +func NewExtraInformation() ExtraInformation { + return internal.NewExtraInformation() } diff --git a/internal/activity.go b/internal/activity.go index 1bfdbe3bd..dcbcaf3aa 100644 --- a/internal/activity.go +++ b/internal/activity.go @@ -60,6 +60,11 @@ type ( IsLocalActivity bool // true if it is a local activity } + // ActivityExtraInformation contains additional data to be sent to the server on activity failure + ActivityExtraInformation struct { + retryDelay *time.Duration + } + // RegisterActivityOptions consists of options for registering an activity RegisterActivityOptions struct { // When an activity is a function the name is an actual activity type name. @@ -353,16 +358,12 @@ func WithLocalActivityTask( }) } -type ActivityExtra struct { - retryDelay *time.Duration -} - -func NewActivityExtra() ActivityExtra { - info := ActivityExtra{} +func NewExtraInformation() ActivityExtraInformation { + info := ActivityExtraInformation{} return info } -func (b ActivityExtra) WithRetryDelay(delay time.Duration) ActivityExtra { +func (b ActivityExtraInformation) WithRetryDelay(delay time.Duration) ActivityExtraInformation { b.retryDelay = &delay return b } diff --git a/internal/error.go b/internal/error.go index c09e53751..f32b68703 100644 --- a/internal/error.go +++ b/internal/error.go @@ -138,16 +138,6 @@ type ( extra ExtraInformation } - ApplicationErrorWithRetryDelay struct { - temporalError - msg string - errType string - retryDelay time.Duration - cause error - nonRetryable bool - details converter.EncodedValues - } - // TimeoutError returned when activity or child workflow timed out. TimeoutError struct { temporalError diff --git a/internal/extra_information.go b/internal/extra_information.go index 1c3cdcf50..1c92677e4 100644 --- a/internal/extra_information.go +++ b/internal/extra_information.go @@ -2,12 +2,3 @@ package internal type ExtraInformation interface { } - -//type ActivityExtraInformation struct { -// retryDelaySet bool -// retryDelay time.Duration -//} -// -//func (extra *ActivityExtraInformation) RetryDelay() (time.Duration, bool) { -// return extra.retryDelay, extra.retryDelaySet -//} diff --git a/internal/failure_converter.go b/internal/failure_converter.go index e47f9de43..41311a764 100644 --- a/internal/failure_converter.go +++ b/internal/failure_converter.go @@ -97,13 +97,6 @@ func (dfc *DefaultFailureConverter) ErrorToFailure(err error) *failurepb.Failure Details: convertErrDetailsToPayloads(err.details, dfc.dataConverter), } failure.FailureInfo = &failurepb.Failure_ApplicationFailureInfo{ApplicationFailureInfo: failureInfo} - //case *ApplicationErrorWithRetryDelay: - // failureInfo := &failurepb.ApplicationFailureInfo{ - // Type: err.errType, - // NonRetryable: false, - // Details: convertErrDetailsToPayloads(err.details, dfc.dataConverter), - // } - // failure.FailureInfo = &failurepb.Failure_ApplicationFailureInfo{ApplicationFailureInfo: failureInfo} case *CanceledError: failureInfo := &failurepb.CanceledFailureInfo{ Details: convertErrDetailsToPayloads(err.details, dfc.dataConverter), diff --git a/internal/internal_task_pollers.go b/internal/internal_task_pollers.go index 77bd57cd2..01ed12043 100644 --- a/internal/internal_task_pollers.go +++ b/internal/internal_task_pollers.go @@ -1235,7 +1235,7 @@ func extractActivityRequestsFrom(err error) *commonpb.ActivityRequests { if !ok { return requests } - activityExtra, ok := applicationError.extra.(*ActivityExtra) + activityExtra, ok := applicationError.extra.(*ActivityExtraInformation) if !ok || activityExtra.retryDelay == nil { return requests } diff --git a/temporal/error.go b/temporal/error.go index fdd15ac74..6e2271cc5 100644 --- a/temporal/error.go +++ b/temporal/error.go @@ -168,17 +168,9 @@ var ( ErrSkipScheduleUpdate = internal.ErrSkipScheduleUpdate ) -// Use instance of the interface to set all the desired attributes of a new ApplicationError +// ApplicationErrorAttributes should be used to set all the desired attributes of a new ApplicationError // To get a new instance use ErrorAttributes function -type ApplicationErrorAttributes interface { - WithMessage(string) ApplicationErrorAttributes - WithErrorType(errType string) ApplicationErrorAttributes - WithRetryable(isRetryable bool) ApplicationErrorAttributes - WithDetails(details ...interface{}) ApplicationErrorAttributes - asErrorAttributes() internal.ErrorAttributes -} - -type errorAttributeStorage struct { +type ApplicationErrorAttributes struct { message string errType string isRetryable bool @@ -186,60 +178,60 @@ type errorAttributeStorage struct { details []interface{} } -type errorAttributesImpl = errorAttributeStorage +type errorAttributes = ApplicationErrorAttributes // Produce a new instance compliant with ApplicationErrorAttributes func ErrorAttributes() ApplicationErrorAttributes { - attrs := errorAttributeStorage{isRetryable: true} + attrs := ApplicationErrorAttributes{isRetryable: true} return attrs } -func (b errorAttributeStorage) WithMessage(message string) ApplicationErrorAttributes { +func (b ApplicationErrorAttributes) WithMessage(message string) ApplicationErrorAttributes { b.message = message return b } -func (b errorAttributeStorage) WithErrorType(errType string) ApplicationErrorAttributes { +func (b ApplicationErrorAttributes) WithErrorType(errType string) ApplicationErrorAttributes { b.errType = errType return b } -func (b errorAttributeStorage) WithRetryable(isRetryable bool) ApplicationErrorAttributes { +func (b ApplicationErrorAttributes) WithRetryable(isRetryable bool) ApplicationErrorAttributes { b.isRetryable = isRetryable return b } -func (b errorAttributeStorage) WithDetails(details ...interface{}) ApplicationErrorAttributes { +func (b ApplicationErrorAttributes) WithDetails(details ...interface{}) ApplicationErrorAttributes { b.details = details return b } -func (b errorAttributeStorage) WithCause(cause error) ApplicationErrorAttributes { +func (b ApplicationErrorAttributes) WithCause(cause error) ApplicationErrorAttributes { b.cause = cause return b } -func (b errorAttributeStorage) asErrorAttributes() internal.ErrorAttributes { - return errorAttributesImpl(b) +func (b ApplicationErrorAttributes) asErrorAttributes() internal.ErrorAttributes { + return errorAttributes(b) } -func (b errorAttributesImpl) Message() string { +func (b errorAttributes) Message() string { return b.message } -func (b errorAttributesImpl) ErrType() string { +func (b errorAttributes) ErrType() string { return b.errType } -func (b errorAttributesImpl) IsRetryable() bool { +func (b errorAttributes) IsRetryable() bool { return b.isRetryable } -func (b errorAttributesImpl) Cause() error { +func (b errorAttributes) Cause() error { return b.cause } -func (b errorAttributesImpl) Details() []interface{} { +func (b errorAttributes) Details() []interface{} { return b.details[:] }