Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit b0d9944

Browse files
Clément Le ProvostPLNech
authored andcommitted
Add a variant of waitTask with integer task ID (#343)
The `taskID` field returned by the API is always an integer. Exposing a string in the API Client is confusing. => This change exposes an overloaded method with integer argument, and deprecates the string variant.
1 parent 205be7c commit b0d9944

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

algoliasearch/src/main/java/com/algolia/search/saas/Index.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ public Request getObjectsAsync(final @NonNull List<String> objectIDs, final List
479479
* @param taskID Identifier of the task (as returned by the server).
480480
* @param completionHandler The listener that will be notified of the request's outcome.
481481
* @return A cancellable request.
482+
*
483+
* @deprecated Task IDs are always integers. Please use {@link #waitTaskAsync(int, CompletionHandler)} instead.
482484
*/
483485
public Request waitTaskAsync(final @NonNull String taskID, @NonNull CompletionHandler completionHandler) {
484486
return getClient().new AsyncTaskRequest(completionHandler) {
@@ -489,6 +491,23 @@ public Request waitTaskAsync(final @NonNull String taskID, @NonNull CompletionHa
489491
}.start();
490492
}
491493

494+
/**
495+
* Wait until the publication of a task on the server (helper).
496+
* All server tasks are asynchronous. This method helps you check that a task is published.
497+
*
498+
* @param taskID Identifier of the task (as returned by the server).
499+
* @param completionHandler The listener that will be notified of the request's outcome.
500+
* @return A cancellable request.
501+
*/
502+
public Request waitTaskAsync(final int taskID, @NonNull CompletionHandler completionHandler) {
503+
return getClient().new AsyncTaskRequest(completionHandler) {
504+
@NonNull
505+
@Override protected JSONObject run() throws AlgoliaException {
506+
return waitTask(Integer.toString(taskID));
507+
}
508+
}.start();
509+
}
510+
492511
/**
493512
* Delete an object from this index (asynchronously).
494513
*

algoliasearch/src/test/java/com/algolia/search/saas/IndexTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public void waitTaskAsync() throws Exception {
452452
index.addObjectAsync(new JSONObject("{\"city\": \"New York\"}"), new AssertCompletionHandler() {
453453
@Override public void doRequestCompleted(JSONObject content, AlgoliaException error) {
454454
if (error == null) {
455-
index.waitTaskAsync(content.optString("taskID"), new AssertCompletionHandler() {
455+
index.waitTaskAsync(content.optInt("taskID"), new AssertCompletionHandler() {
456456
@Override
457457
public void doRequestCompleted(JSONObject content, AlgoliaException error) {
458458
if (error == null) {

0 commit comments

Comments
 (0)