public static TaskResourceRep waitForTask(RestClient client, TaskResourceRep task, long timeoutMillis) {
long startTime = System.currentTimeMillis();
while (isRunning(task)) {
if (timeoutMillis > 0 && (System.currentTimeMillis() - startTime) > timeoutMillis) {
throw new TimeoutException("Timed out waiting for task to complete");
}
try {
Thread.sleep(client.getConfig().getTaskPollingInterval());
}
catch (InterruptedException e) {