-
Notifications
You must be signed in to change notification settings - Fork 14
Added support for retry policies #23
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
sdk/src/main/java/com/microsoft/durabletask/RetryPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| package com.microsoft.durabletask; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.time.Duration; | ||
| import java.util.Objects; | ||
|
|
||
| public class RetryPolicy { | ||
|
|
||
| private final int maxNumberOfAttempts; | ||
| private final Duration firstRetryInterval; | ||
| private final double backoffCoefficient; | ||
| private final Duration maxRetryInterval; | ||
| private final Duration retryTimeout; | ||
|
|
||
| private RetryPolicy(Builder builder) { | ||
| this.maxNumberOfAttempts = builder.maxNumberOfAttempts; | ||
| this.firstRetryInterval = builder.firstRetryInterval; | ||
| this.backoffCoefficient = builder.backoffCoefficient; | ||
| this.maxRetryInterval = Objects.requireNonNullElse(builder.maxRetryInterval, Duration.ZERO); | ||
| this.retryTimeout = Objects.requireNonNullElse(builder.retryTimeout, Duration.ZERO); | ||
| } | ||
|
|
||
| public static Builder newBuilder(int maxNumberOfAttempts, Duration firstRetryInterval) { | ||
| return new Builder(maxNumberOfAttempts, firstRetryInterval); | ||
| } | ||
|
|
||
| public int getMaxNumberOfAttempts() { | ||
| return this.maxNumberOfAttempts; | ||
| } | ||
|
|
||
| public Duration getFirstRetryInterval() { | ||
| return this.firstRetryInterval; | ||
| } | ||
|
|
||
| public double getBackoffCoefficient() { | ||
| return this.backoffCoefficient; | ||
| } | ||
|
|
||
| public Duration getMaxRetryInterval() { | ||
| return this.maxRetryInterval; | ||
| } | ||
|
|
||
| public Duration getRetryTimeout() { | ||
| return this.retryTimeout; | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private int maxNumberOfAttempts; | ||
| private Duration firstRetryInterval; | ||
| private double backoffCoefficient; | ||
| private Duration maxRetryInterval; | ||
| private Duration retryTimeout; | ||
|
|
||
| private Builder(int maxNumberOfAttempts, Duration firstRetryInterval) { | ||
| this.setMaxNumberOfAttempts(maxNumberOfAttempts); | ||
| this.setFirstRetryInterval(firstRetryInterval); | ||
| } | ||
|
|
||
| public RetryPolicy build() { | ||
| return new RetryPolicy(this); | ||
| } | ||
|
|
||
| public Builder setMaxNumberOfAttempts(int maxNumberOfAttempts) { | ||
| if (maxNumberOfAttempts <= 0) { | ||
| throw new IllegalArgumentException("The value for maxNumberOfAttempts must be greater than zero."); | ||
| } | ||
| this.maxNumberOfAttempts = maxNumberOfAttempts; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setFirstRetryInterval(Duration firstRetryInterval) { | ||
| if (firstRetryInterval == null) { | ||
| throw new IllegalArgumentException("firstRetryInterval cannot be null."); | ||
| } | ||
| if (firstRetryInterval.isZero() || firstRetryInterval.isNegative()) { | ||
| throw new IllegalArgumentException("The value for firstRetryInterval must be greater than zero."); | ||
| } | ||
| this.firstRetryInterval = firstRetryInterval; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setBackoffCoefficient(double backoffCoefficient) { | ||
| if (backoffCoefficient < 1.0) { | ||
| throw new IllegalArgumentException("The value for backoffCoefficient must be greater or equal to 1.0."); | ||
| } | ||
| this.backoffCoefficient = backoffCoefficient; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setMaxRetryInterval(@Nullable Duration maxRetryInterval) { | ||
| if (maxRetryInterval != null && maxRetryInterval.compareTo(this.firstRetryInterval) < 0) { | ||
| throw new IllegalArgumentException("The value for maxRetryInterval must be greater than or equal to the value for firstRetryInterval."); | ||
| } | ||
| this.maxRetryInterval = maxRetryInterval; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setRetryTimeout(Duration retryTimeout) { | ||
| if (retryTimeout != null && retryTimeout.compareTo(this.firstRetryInterval) < 0) { | ||
| throw new IllegalArgumentException("The value for retryTimeout must be greater than or equal to the value for firstRetryInterval."); | ||
| } | ||
| this.retryTimeout = retryTimeout; | ||
| return this; | ||
| } | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
sdk/src/main/java/com/microsoft/durabletask/TaskOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| package com.microsoft.durabletask; | ||
|
|
||
| public class TaskOptions { | ||
| private final RetryPolicy retryPolicy; | ||
|
|
||
| TaskOptions(Builder builder) { | ||
| this.retryPolicy = builder.retryPolicy; | ||
| } | ||
|
|
||
| public static TaskOptions fromRetryPolicy(RetryPolicy policy) { | ||
| return newBuilder().setRetryPolicy(policy).build(); | ||
| } | ||
|
|
||
| boolean hasRetryPolicy() { | ||
| return this.retryPolicy != null; | ||
| } | ||
|
|
||
| public RetryPolicy getRetryPolicy() { | ||
| return this.retryPolicy; | ||
| } | ||
|
|
||
| public static Builder newBuilder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
| private RetryPolicy retryPolicy; | ||
|
|
||
| private Builder() { | ||
| } | ||
|
|
||
| public TaskOptions build() { | ||
| return new TaskOptions(this); | ||
| } | ||
|
|
||
| public Builder setRetryPolicy(RetryPolicy retryPolicy) { | ||
| this.retryPolicy = retryPolicy; | ||
| return this; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.