Skip to content

Commit

Permalink
applying code review comments, removing dead code, adding godoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ast2023 committed Dec 13, 2023
1 parent d57a74c commit c180126
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 61 deletions.
10 changes: 7 additions & 3 deletions activity/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
15 changes: 8 additions & 7 deletions internal/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 0 additions & 10 deletions internal/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions internal/extra_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//}
7 changes: 0 additions & 7 deletions internal/failure_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion internal/internal_task_pollers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
40 changes: 16 additions & 24 deletions temporal/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,78 +168,70 @@ 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
cause error
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[:]
}

Expand Down

0 comments on commit c180126

Please sign in to comment.