class ExecutionService {

    public String getQualityStatus(long projectId, String jobUrl) {
        final Execution execution = executionRepository.findByProjectIdAndJobUrl(projectId, jobUrl);

        // Not indexed yet (plus, if the completionRequested flag is set and the execution crashed with no usable data,
        // it will get indexed (as CRASHED) next time the crawler run)
        if (execution == null) {
            return STILL_COMPUTING; // Please call getQualityStatus later: status will be set soon
        }

        // When DONE, an execution will not be re-indexed anymore (we have the definitive data), no matter if the flag is set or not
        if (execution.getStatus() != JobStatus.DONE) {
            final Optional<ExecutionCompletionRequest> request = executionCompletionRequestRepository.findById(jobUrl);
            if (request.isPresent()) {
                return STILL_COMPUTING; // Please call getQualityStatus later: status will be set soon
            }
        }

        if (crashed(execution)) {
            return "CRASHED";
        } else if (execution.getBlockingValidation() != Boolean.TRUE) {
            return "NOT_BLOCKING";
        } else if (StringUtils.isNotEmpty(execution.getDiscardReason())) {
            return "DISCARDED";
        }

        // We have the definitive data (or completionRequested was never called beforehand: not our problem)
        return (execution.getQualityStatus() == null ? QualityStatus.INCOMPLETE : execution.getQualityStatus()).name();
    }

}