Skip to content

Commit

Permalink
change retry interval
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed May 22, 2024
1 parent 263ca40 commit ba3a6a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/main/java/com/crowdin/cli/client/CrowdinClientCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ protected static <T> List<T> executeRequestFullList(BiFunction<Integer, Integer,
return directories;
}

protected static <T> T executeRequestWithPossibleRetry(Map<BiPredicate<String, String>, ResponseException> errorHandlers, Supplier<T> request) throws ResponseException {
return executeRequestWithPossibleRetries(errorHandlers, request, 2, defaultMillisToRetry);
}

protected static <T> T executeRequestWithPossibleRetries(Map<BiPredicate<String, String>, ResponseException> errorHandlers, Supplier<T> request, int maxAttempts, long millisToRetry) throws ResponseException {
if (maxAttempts < 1) {
throw new MaxNumberOfRetriesException();
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Long uploadStorage(String fileName, InputStream content) throws Response
errorHandlers,
() -> this.client.getStorageApi().addStorage(fileName, content).getData(),
3,
6 * 1000
2 * 1000
);
return storage.getId();
}
Expand Down Expand Up @@ -258,10 +258,12 @@ public void updateSource(Long sourceId, UpdateFileRequest request) throws Respon
put((code, message) -> StringUtils.contains(message, "Invalid SRX specified"), new ResponseException("Invalid SRX file specified"));
put((code, message) -> code.equals("409"), new FileInUpdateException());
}};
executeRequestWithPossibleRetry(
executeRequestWithPossibleRetries(
errorHandlers,
() -> this.client.getSourceFilesApi()
.updateOrRestoreFile(this.projectId, sourceId, request));
() -> this.client.getSourceFilesApi().updateOrRestoreFile(this.projectId, sourceId, request),
3,
2 * 1000
);
}

@Override
Expand All @@ -275,10 +277,12 @@ public FileInfo addSource(AddFileRequest request) throws ResponseException {
put((code, message) -> StringUtils.contains(message, "Invalid SRX specified"), new ResponseException("Invalid SRX file specified"));
put((code, message) -> StringUtils.containsAny(message, "isEmpty", "Value is required and can't be empty"), new EmptyFileException("Value is required and can't be empty"));
}};
return executeRequestWithPossibleRetry(
return executeRequestWithPossibleRetries(
errorHandlers,
() -> this.client.getSourceFilesApi()
.addFile(this.projectId, request).getData());
() -> this.client.getSourceFilesApi().addFile(this.projectId, request).getData(),
3,
2 * 1000
);
}

@Override
Expand Down Expand Up @@ -325,7 +329,7 @@ public void uploadTranslations(String languageId, UploadTranslationsRequest requ
errorhandlers,
() -> this.client.getTranslationsApi().uploadTranslations(this.projectId, languageId, request),
3,
6 * 1000
2 * 1000
);
}

Expand Down

0 comments on commit ba3a6a0

Please sign in to comment.