class JobExecutionResultHandler extends AbstractRestHandler<RestfulGateway, EmptyRequestBody, JobExecutionResultResponseBody, JobMessageParameters> {

	@Override
	protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
			@Nonnull final HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
			@Nonnull final RestfulGateway gateway) throws RestHandlerException {

		final JobID jobId = request.getPathParameter(JobIDPathParameter.class);

		final CompletableFuture<JobStatus> jobStatusFuture = gateway.requestJobStatus(jobId, timeout);

		return jobStatusFuture.thenCompose(
			jobStatus -> {
				if (jobStatus.isGloballyTerminalState()) {
					return gateway
						.requestJobResult(jobId, timeout)
						.thenApply(JobExecutionResultResponseBody::created);
				} else {
					return CompletableFuture.completedFuture(
						JobExecutionResultResponseBody.inProgress());
				}
			}).exceptionally(throwable -> {
				throw propagateException(throwable);
			});
	}

	public  JobExecutionResultHandler(
			final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
			final Time timeout,
			final Map<String, String> responseHeaders);

}