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

added exponential delay for poisoned message handlers #175

Merged
merged 9 commits into from
Aug 26, 2022

Conversation

Peppi-Ressler
Copy link
Contributor

Added optional exponential delay for republishing messages.

@Peppi-Ressler Peppi-Ressler self-assigned this Apr 11, 2022
Comment on lines 6 to 19
class ExponentialDelay(initialDelay: Duration, period: Duration, factor: Double, maxLength: Duration) {
private val maxMillis = maxLength.toMillis

def getExponentialDelay(attempts: Int): FiniteDuration = {
if (attempts == 0) FiniteDuration(initialDelay._1, initialDelay._2)
else {
val millis = math.min(
maxMillis,
(period.toMillis * math.pow(factor, attempts - 1)).toLong
)
FiniteDuration(millis, TimeUnit.MILLISECONDS)
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class ExponentialDelay(initialDelay: Duration, period: Duration, factor: Double, maxLength: Duration) {
private val maxMillis = maxLength.toMillis
def getExponentialDelay(attempts: Int): FiniteDuration = {
if (attempts == 0) FiniteDuration(initialDelay._1, initialDelay._2)
else {
val millis = math.min(
maxMillis,
(period.toMillis * math.pow(factor, attempts - 1)).toLong
)
FiniteDuration(millis, TimeUnit.MILLISECONDS)
}
}
}
class ExponentialDelay(initialDelay: Duration, period: Duration, factor: Double, maxLength: Duration) {
private val maxMillis = maxLength.toMillis
def getExponentialDelay(attempt: Int): FiniteDuration = {
if (attempt == 0) FiniteDuration(initialDelay._1, initialDelay._2)
else {
val millis = math.min(
maxMillis,
(period.toMillis * math.pow(factor, attempt - 1)).toLong
)
FiniteDuration(millis, TimeUnit.MILLISECONDS)
}
}
}

Copy link
Collaborator

@jendakol jendakol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In overall, it looks good.
I have only two problems:

  1. Default republish delays - 5 seconds is a weird value :-D But this is not a blocker, if you insist. I'd use just 2 seconds instead ;-)
  2. The functionality is not tested. I believe it should be a part of some test case in PoisonedMessageHandlerTest.

Copy link
Collaborator

@jendakol jendakol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

@Peppi-Ressler Peppi-Ressler merged commit 4408887 into master Aug 26, 2022
@Peppi-Ressler Peppi-Ressler deleted the exponential-delay branch August 26, 2022 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants