[Draft]: Added Exponential Retry Mechanism with Idempotency Headers#92
[Draft]: Added Exponential Retry Mechanism with Idempotency Headers#92git-ashug wants to merge 2 commits intonovuhq:stagingfrom
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.
I think these should be false by default
mayorjay
left a comment
There was a problem hiding this comment.
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.
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
| Response response = null; | ||
| IOException lastException = null; | ||
|
|
||
| for (int retry = 0; retry < maxRetries; retry++) { |
There was a problem hiding this comment.
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.
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.
@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.
okhttp3library, I have used the same library to implement the requirement asInterceptors.Will keep you updated as I progress on this issue.