Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move RetryActivity to the corresponding file #6038

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"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 @@

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

Check warning on line 728 in service/history/execution/mutable_state_builder_methods_activity.go

View check run for this annotation

Codecov / codecov/patch

service/history/execution/mutable_state_builder_methods_activity.go#L728

Added line #L728 was not covered by tests
}

if !ai.HasRetryPolicy || ai.CancelRequested {
return false, nil

Check warning on line 732 in service/history/execution/mutable_state_builder_methods_activity.go

View check run for this annotation

Codecov / codecov/patch

service/history/execution/mutable_state_builder_methods_activity.go#L732

Added line #L732 was not covered by tests
}

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

Check warning on line 749 in service/history/execution/mutable_state_builder_methods_activity.go

View check run for this annotation

Codecov / codecov/patch

service/history/execution/mutable_state_builder_methods_activity.go#L749

Added line #L749 was not covered by tests
}

// 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

Check warning on line 767 in service/history/execution/mutable_state_builder_methods_activity.go

View check run for this annotation

Codecov / codecov/patch

service/history/execution/mutable_state_builder_methods_activity.go#L767

Added line #L767 was not covered by tests
}

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
}
Loading