-
Notifications
You must be signed in to change notification settings - Fork 22
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
[Draft]: Added Exponential Retry Mechanism with Idempotency Headers #92
base: staging
Are you sure you want to change the base?
[Draft]: Added Exponential Retry Mechanism with Idempotency Headers #92
Conversation
@mayorJAY Please review |
private boolean enableRetry = true; // To enable/disable retry logic | ||
private boolean enableIdempotencyKey = true; // To enable/disable idempotency key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should be false by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can refer to this comment for more guidance on the requirement novuhq/novu#4462 (comment)
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
public class IdempotencyKeyInterceptor implements Interceptor{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't necessarily need a dedicated Interceptor for this. We can make it a dynamic header by using @ Headers for the POST and PATCH calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Response response = null; | ||
IOException lastException = null; | ||
|
||
for (int retry = 0; retry < maxRetries; retry++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use a while loop instead. Something like this while (!response.isSuccessful() && retry < maxRetries) {}
This will ensure that we're attempting the retrial only when the last call was not successful.
Also, note that the check for a successful call should be based on the the status codes specified here. You can have a utility function that does this check
if(novuConfig.isEnableIdempotencyKey()) { | ||
clientBuilder.addInterceptor(new IdempotencyKeyInterceptor()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason why this can't be done is the fact that we provide the Retrofit instance lazily (see lines 27 to 29). Doing this would mean that every request will use the same value as the Idempotency-Key
, which is not the goal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mayorJAY I tried this interceptor and it is inputting new header value for each request made
Related to #79
Hi @Cliftonz,
Please review this Draft PR as I am progressing on it.
okhttp3
library, I have used the same library to implement the requirement asInterceptors
.Will keep you updated as I progress on this issue.