use of bio.terra.workspace.service.job.exception.JobNotCompleteException in project terra-workspace-manager by DataBiosphere.
the class JobService method retrieveJobResultWorker.
private <T> JobResultOrException<T> retrieveJobResultWorker(String jobId, Class<T> resultClass) throws StairwayException, InterruptedException {
FlightState flightState = stairwayComponent.get().getFlightState(jobId);
FlightMap resultMap = flightState.getResultMap().orElse(null);
if (resultMap == null) {
throw new InvalidResultStateException("No result map returned from flight");
}
switch(flightState.getFlightStatus()) {
case FATAL:
case ERROR:
if (flightState.getException().isPresent()) {
Exception exception = flightState.getException().get();
if (exception instanceof RuntimeException) {
return new JobResultOrException<T>().exception((RuntimeException) exception);
} else {
return new JobResultOrException<T>().exception(new JobResponseException("wrap non-runtime exception", exception));
}
}
throw new InvalidResultStateException("Failed operation with no exception reported");
case SUCCESS:
return new JobResultOrException<T>().result(resultMap.get(JobMapKeys.RESPONSE.getKeyName(), resultClass));
case RUNNING:
throw new JobNotCompleteException("Attempt to retrieve job result before job is complete; job id: " + flightState.getFlightId());
default:
throw new InvalidResultStateException("Impossible case reached");
}
}
Aggregations