diff --git a/service/history/execution/mutable_state_builder_methods_activity.go b/service/history/execution/mutable_state_builder_methods_activity.go index 674010be50d..2dfd6d4b7df 100644 --- a/service/history/execution/mutable_state_builder_methods_activity.go +++ b/service/history/execution/mutable_state_builder_methods_activity.go @@ -28,6 +28,7 @@ import ( "time" "github.com/uber/cadence/common" + "github.com/uber/cadence/common/backoff" "github.com/uber/cadence/common/log/tag" "github.com/uber/cadence/common/metrics" "github.com/uber/cadence/common/persistence" @@ -715,3 +716,58 @@ func (e *mutableStateBuilder) ReplicateActivityTaskCanceledEvent( return e.DeleteActivity(scheduleID) } + +func (e *mutableStateBuilder) RetryActivity( + ai *persistence.ActivityInfo, + failureReason string, + failureDetails []byte, +) (bool, error) { + + opTag := tag.WorkflowActionActivityTaskRetry + if err := e.checkMutability(opTag); err != nil { + return false, err + } + + if !ai.HasRetryPolicy || ai.CancelRequested { + return false, nil + } + + now := e.timeSource.Now() + + backoffInterval := getBackoffInterval( + now, + ai.ExpirationTime, + ai.Attempt, + ai.MaximumAttempts, + ai.InitialInterval, + ai.MaximumInterval, + ai.BackoffCoefficient, + failureReason, + ai.NonRetriableErrors, + ) + if backoffInterval == backoff.NoBackoff { + return false, nil + } + + // a retry is needed, update activity info for next retry + ai.Version = e.GetCurrentVersion() + ai.Attempt++ + ai.ScheduledTime = now.Add(backoffInterval) // update to next schedule time + ai.StartedID = common.EmptyEventID + ai.RequestID = "" + ai.StartedTime = time.Time{} + ai.TimerTaskStatus = TimerTaskStatusNone + ai.LastFailureReason = failureReason + ai.LastWorkerIdentity = ai.StartedIdentity + ai.LastFailureDetails = failureDetails + + if err := e.taskGenerator.GenerateActivityRetryTasks( + ai.ScheduleID, + ); err != nil { + return false, err + } + + e.updateActivityInfos[ai.ScheduleID] = ai + e.syncActivityTasks[ai.ScheduleID] = struct{}{} + return true, nil +} diff --git a/service/history/execution/mutable_state_builder_methods_child_workflow.go b/service/history/execution/mutable_state_builder_methods_child_workflow.go index 361ed530a27..3d1460fc3f3 100644 --- a/service/history/execution/mutable_state_builder_methods_child_workflow.go +++ b/service/history/execution/mutable_state_builder_methods_child_workflow.go @@ -25,10 +25,8 @@ package execution import ( "context" "fmt" - "time" "github.com/uber/cadence/common" - "github.com/uber/cadence/common/backoff" "github.com/uber/cadence/common/log/tag" "github.com/uber/cadence/common/persistence" "github.com/uber/cadence/common/types" @@ -535,58 +533,3 @@ func (e *mutableStateBuilder) ReplicateChildWorkflowExecutionTimedOutEvent( return e.DeletePendingChildExecution(initiatedID) } - -func (e *mutableStateBuilder) RetryActivity( - ai *persistence.ActivityInfo, - failureReason string, - failureDetails []byte, -) (bool, error) { - - opTag := tag.WorkflowActionActivityTaskRetry - if err := e.checkMutability(opTag); err != nil { - return false, err - } - - if !ai.HasRetryPolicy || ai.CancelRequested { - return false, nil - } - - now := e.timeSource.Now() - - backoffInterval := getBackoffInterval( - now, - ai.ExpirationTime, - ai.Attempt, - ai.MaximumAttempts, - ai.InitialInterval, - ai.MaximumInterval, - ai.BackoffCoefficient, - failureReason, - ai.NonRetriableErrors, - ) - if backoffInterval == backoff.NoBackoff { - return false, nil - } - - // a retry is needed, update activity info for next retry - ai.Version = e.GetCurrentVersion() - ai.Attempt++ - ai.ScheduledTime = now.Add(backoffInterval) // update to next schedule time - ai.StartedID = common.EmptyEventID - ai.RequestID = "" - ai.StartedTime = time.Time{} - ai.TimerTaskStatus = TimerTaskStatusNone - ai.LastFailureReason = failureReason - ai.LastWorkerIdentity = ai.StartedIdentity - ai.LastFailureDetails = failureDetails - - if err := e.taskGenerator.GenerateActivityRetryTasks( - ai.ScheduleID, - ); err != nil { - return false, err - } - - e.updateActivityInfos[ai.ScheduleID] = ai - e.syncActivityTasks[ai.ScheduleID] = struct{}{} - return true, nil -}