Skip to content

Commit

Permalink
Fix bug in Retry logic of Subscribe (forcedotcom#62)
Browse files Browse the repository at this point in the history
* Update batch size usage in Subscribe examples

* Fix bug in retry logic

Signed-off-by: Siddartha Shankar <siddarthashankar@salesforce.com>

---------

Signed-off-by: Siddartha Shankar <siddarthashankar@salesforce.com>
  • Loading branch information
sidd0610 authored and joaoalber committed Sep 3, 2024
1 parent 45a47a3 commit 0805d55
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ These examples are developed by the community. They aren't supported by Salesfor
- [E-Bikes Sample Application](https://github.com/trailheadapps/ebikes-lwc)
- [Pub/Sub API Node Client](https://github.com/pozil/pub-sub-api-node-client)
- [.NET Code Examples](https://github.com/Meyce/pub-sub-api/tree/main/.Net)
- [Ruby Pub/Sub API Example](https://github.com/RenoFi/salesforce-pub-sub-rb)

If you have a code sample for Pub/Sub API that you would like to add a link to in this section, submit a PR with the modified readme page. We don't guarantee that we can link to all samples. Priority will be given to samples implemented in a programming language that is not represented in this repository's samples.
If you have a code sample for Pub/Sub API that you would like to add a link to in this section, submit a PR with the modified readme page. We don't guarantee that we can link to all samples. Priority will be given to samples implemented in a programming language that is not represented in this repository's samples.
36 changes: 19 additions & 17 deletions java/src/main/java/genericpubsub/Subscribe.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,28 +187,30 @@ public void onError(Throwable t) {

ReplayPreset retryReplayPreset = ReplayPreset.LATEST;
ByteString retryReplayId = null;
long retryDelay = 0;
long retryDelay = getBackoffWaitTime();

// Retry strategies that can be implemented based on the error type.
if (errorCode.contains(ERROR_REPLAY_ID_VALIDATION_FAILED) || errorCode.contains(ERROR_REPLAY_ID_INVALID)) {
logger.info("Invalid or no replayId provided in FetchRequest for CUSTOM Replay. Trying again with EARLIEST Replay.");
retryDelay = getBackoffWaitTime();
retryReplayPreset = ReplayPreset.EARLIEST;
} else if (errorCode.contains(ERROR_SERVICE_UNAVAILABLE)) {
logger.info("Service currently unavailable. Trying again with LATEST Replay.");
retryDelay = SERVICE_UNAVAILABLE_WAIT_BEFORE_RETRY_SECONDS * 1000;
} else {
retryDelay = getBackoffWaitTime();
if (storedReplay != null) {
logger.info("Retrying with Stored Replay.");
retryReplayPreset = ReplayPreset.CUSTOM;
retryReplayId = getStoredReplay();
if(errorCode != null && !errorCode.isEmpty()) {
if (errorCode.contains(ERROR_REPLAY_ID_VALIDATION_FAILED) || errorCode.contains(ERROR_REPLAY_ID_INVALID)) {
logger.info("Invalid or no replayId provided in FetchRequest for CUSTOM Replay. Trying again with EARLIEST Replay.");
retryReplayPreset = ReplayPreset.EARLIEST;
} else if (errorCode.contains(ERROR_SERVICE_UNAVAILABLE)) {
logger.info("Service currently unavailable. Trying again with LATEST Replay.");
retryDelay = SERVICE_UNAVAILABLE_WAIT_BEFORE_RETRY_SECONDS * 1000;
} else {
logger.info("Retrying with LATEST Replay.");;
}
if (storedReplay != null) {
logger.info("Retrying with Stored Replay.");
retryReplayPreset = ReplayPreset.CUSTOM;
retryReplayId = getStoredReplay();
} else {
logger.info("Retrying with LATEST Replay.");
}

}
} else {
logger.info("Unknown error. Retrying with LATEST Replay.");
}
logger.info("Retrying in " + retryDelay + "ms.");
logger.info(String.format("Retrying in %s ms.", retryDelay));
retryScheduler.schedule(new RetryRequestSender(retryReplayPreset, retryReplayId), retryDelay, TimeUnit.MILLISECONDS);
}
}
Expand Down

0 comments on commit 0805d55

Please sign in to comment.