Skip to content

Commit

Permalink
Move RetryActivity to the corresponding file (cadence-workflow#6038)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll authored and timl3136 committed Jun 6, 2024
1 parent 6520956 commit 5f4d819
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 5f4d819

Please sign in to comment.