Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Fix: remove failure counter
Browse files Browse the repository at this point in the history
Since we're using a lock, there is no need anymore to stop retrying async call
after 100 attempts.

Signed-off-by: Gloria Ciavarrini <gciavarrini@redhat.com>
  • Loading branch information
gciavarrini committed Apr 14, 2023
1 parent 31b9416 commit 934ce1d
Showing 1 changed file with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
Expand All @@ -32,23 +31,14 @@ public static void waitProjectStart(ProjectApi projectApi) throws ApiException,
Lock lock = new ReentrantLock();
Condition response = lock.newCondition();
ApiCallback<List<ProjectResponseDTO>> apiCallback = new ApiCallback<>() {
AtomicInteger failureCounter = new AtomicInteger(0);

@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
int i = failureCounter.incrementAndGet();
if (i >= 100) {
asyncResult.setError(e.getMessage());
signal();
try {
projectApi.getProjectsAsync(this);
}
else {
try {
projectApi.getProjectsAsync(this);
}
catch (ApiException apie) {
asyncResult.setError(apie.getMessage());
signal();
}
catch (ApiException apie) {
asyncResult.setError(apie.getMessage());
signal();
}
}

Expand Down Expand Up @@ -82,7 +72,7 @@ private void signal() {
// should be more than enough
response.await(60, TimeUnit.SECONDS);
if (asyncResult.getError() != null) {
fail("An error occurred while executing getProjectsAsync: " + asyncResult.getError());
fail("An error occurred while executing getProjectAsync: " + asyncResult.getError());
}
}
finally {
Expand All @@ -96,35 +86,23 @@ public static WorkFlowStatusResponseDTO waitAsyncStatusResponse(WorkflowApi work
Lock lock = new ReentrantLock();
Condition response = lock.newCondition();
ApiCallback<WorkFlowStatusResponseDTO> apiCallback = new ApiCallback<>() {
AtomicInteger attemptCounter = new AtomicInteger(0);

@Override
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
int i = attemptCounter.incrementAndGet();
if (i >= 100) {
asyncResult.setError(e.getMessage());
signal();
System.out.println("onFAILURE");
try {
workflowApi.getStatusAsync(workFlowExecutionId, this);
}
else {
try {
workflowApi.getStatusAsync(workFlowExecutionId, this);
}
catch (ApiException apie) {
asyncResult.setError(apie.getMessage());
signal();
}
catch (ApiException apie) {
asyncResult.setError(apie.getMessage());
signal();
}
}

@Override
public void onSuccess(WorkFlowStatusResponseDTO result, int statusCode,
Map<String, List<String>> responseHeaders) {
int i = attemptCounter.incrementAndGet();
if (i >= 100) {
asyncResult.setError("Workflow status isn't COMPLETE");
signal();
}
else if (!result.getStatus().equals(WorkStatus.COMPLETED.toString())) {
if (!result.getStatus().equals(WorkStatus.COMPLETED.toString())) {
try {
workflowApi.getStatusAsync(workFlowExecutionId, this);
}
Expand All @@ -136,6 +114,8 @@ else if (!result.getStatus().equals(WorkStatus.COMPLETED.toString())) {
else {
asyncResult.setStatusCode(statusCode);
asyncResult.setResult(result);
asyncResult.setError(null);
signal();
}

}
Expand Down Expand Up @@ -163,8 +143,9 @@ private void signal() {
try {
// should be more than enough
response.await(60, TimeUnit.SECONDS);

if (asyncResult.getError() != null) {
fail("An error occurred while executing getProjectsAsync: " + asyncResult.getError());
fail("An error occurred while executing waitAsyncStatusResponse: " + asyncResult.getError());
}
}
finally {
Expand Down

0 comments on commit 934ce1d

Please sign in to comment.