try {
if (shouldTrace) {
client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)).withResponseFilterLast(new ClientRequestTrackingHandler(invocationId));
}
JobCollectionUpdateResponse response = client2.getJobCollectionsOperations().beginUpdatingAsync(cloudServiceName, jobCollectionName, parameters).get();
SchedulerOperationStatusResponse result = client2.getOperationStatusAsync(response.getRequestId()).get();
int delayInSeconds = 15;
if (client2.getLongRunningOperationInitialTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationInitialTimeout();
}
while ((result.getStatus() != SchedulerOperationStatus.InProgress) == false) {
Thread.sleep(delayInSeconds * 1000);
result = client2.getOperationStatusAsync(response.getRequestId()).get();
delayInSeconds = 10;
if (client2.getLongRunningOperationRetryTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationRetryTimeout();
}
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
if (result.getStatus() != SchedulerOperationStatus.Succeeded) {
if (result.getError() != null) {
ServiceException ex = new ServiceException(result.getError().getCode() + " : " + result.getError().getMessage());
ex.setErrorCode(result.getError().getCode());
ex.setErrorMessage(result.getError().getMessage());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
} else {
ServiceException ex = new ServiceException("");
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
}
result.setETag(response.getETag());
return result;
} finally {
if (client2 != null && shouldTrace) {
client2.close();
}