return pollUntilUnqueuedOrCancelled(stub, monitor, soql, onGoingRequest);
}
ContainerAsyncRequest pollUntilUnqueuedOrCancelled(ToolingStubExt stub, IProgressMonitor monitor, String soql,
ContainerAsyncRequest onGoingRequest) throws ForceRemoteException {
QueryResult queryResult;
int delayMultipler = 1;
while (onGoingRequest.getState().equalsIgnoreCase("queued")) {
try {
Thread.sleep(POLL_INTERVAL * delayMultipler++);
if (monitor.isCanceled()) { // The user has canceled the task
ContainerAsyncRequest abortedRequest = new ContainerAsyncRequest();
abortedRequest.setId(onGoingRequest.getId());
abortedRequest.setState("Aborted");
stub.update(new SObject[] { abortedRequest });
return abortedRequest;
}
} catch (InterruptedException e) {
logger.debug("Exception while polling for ContainerAsyncRequest: ", e);
}
queryResult = stub.query(soql);
onGoingRequest = (ContainerAsyncRequest) queryResult.getRecords()[0];
}
return onGoingRequest;
}