Skip to content

Commit

Permalink
Next retry delay should not be bounded by retry policy MaximumInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
gow committed Jun 4, 2024
1 parent 77a380c commit 5a4a482
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion service/history/workflow/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ func newActivityVisitor(
}

now := timesource.Now().In(time.UTC)
retryMaxInterval := ai.RetryMaximumInterval
delay := nextRetryDelayFrom(failure)

// if a delay is specified by the application it should override the maximum interval set by the retry policy.
if delay != nil {
retryMaxInterval = durationpb.New(*delay)
}

backoff, retryState := nextBackoffInterval(
now,
ai.Attempt,
ai.RetryMaximumAttempts,
ai.RetryInitialInterval,
ai.RetryMaximumInterval,
retryMaxInterval,
ai.RetryExpirationTime,
ai.RetryBackoffCoefficient,
makeBackoffAlgorithm(delay),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ func (s *retryActivitySuite) TestRetryActivity_should_be_scheduled_when_next_ret
s.assertTruncateFailureCalled()
}

func (s *retryActivitySuite) TestRetryActivity_next_retry_delay_should_override_max_interval() {
s.mutableState.timeSource = s.timeSource
taskGeneratorMock := NewMockTaskGenerator(s.controller)
nextAttempt := s.activity.Attempt + 1
expectedScheduledTime := s.timeSource.Now().Add(3 * time.Minute).UTC()
taskGeneratorMock.EXPECT().GenerateActivityRetryTasks(s.activity.ScheduledEventId, expectedScheduledTime, nextAttempt)
s.mutableState.taskGenerator = taskGeneratorMock

s.failure.GetApplicationFailureInfo().NextRetryDelay = durationpb.New(3 * time.Minute)
s.activity.RetryMaximumInterval = durationpb.New(2 * time.Minute) // set retry max interval to be less than next retry delay duration.
_, err := s.mutableState.RetryActivity(s.activity, s.failure)
s.NoError(err)
s.Equal(s.activity.Attempt, nextAttempt)

s.Equal(expectedScheduledTime, s.activity.ScheduledTime.AsTime(), "Activity scheduled time is incorrect")
s.assertTruncateFailureCalled()
}

func (s *retryActivitySuite) TestRetryActivity_when_no_next_backoff_interval_should_fail() {
taskGeneratorMock := NewMockTaskGenerator(s.controller)
s.mutableState.taskGenerator = taskGeneratorMock
Expand Down

0 comments on commit 5a4a482

Please # to comment.