use of org.folio.rest.jaxrs.model.StatusDto.Status.ERROR in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method updateSnapshotStatus.
private Future<JobExecution> updateSnapshotStatus(JobExecution jobExecution, OkapiConnectionParams params) {
Promise<JobExecution> promise = Promise.promise();
Snapshot snapshot = new Snapshot().withJobExecutionId(jobExecution.getId()).withStatus(Snapshot.Status.fromValue(jobExecution.getStatus().name()));
SourceStorageSnapshotsClient client = new SourceStorageSnapshotsClient(params.getOkapiUrl(), params.getTenantId(), params.getToken());
try {
client.putSourceStorageSnapshotsByJobExecutionId(jobExecution.getId(), null, snapshot, response -> {
if (response.result().statusCode() == HttpStatus.HTTP_OK.toInt()) {
promise.complete(jobExecution);
} else {
jobExecutionDao.updateBlocking(jobExecution.getId(), jobExec -> {
Promise<JobExecution> jobExecutionPromise = Promise.promise();
jobExec.setErrorStatus(JobExecution.ErrorStatus.SNAPSHOT_UPDATE_ERROR);
jobExec.setStatus(JobExecution.Status.ERROR);
jobExec.setUiStatus(JobExecution.UiStatus.ERROR);
jobExec.setCompletedDate(new Date());
jobExecutionPromise.complete(jobExec);
return jobExecutionPromise.future();
}, params.getTenantId()).onComplete(jobExecutionUpdate -> {
String message = "Couldn't update snapshot status for jobExecution with id " + jobExecution.getId();
LOGGER.error(message);
promise.fail(message);
});
}
});
} catch (Exception e) {
LOGGER.error("Error during update for Snapshot with id {}", jobExecution.getId(), e);
promise.fail(e);
}
return promise.future();
}
use of org.folio.rest.jaxrs.model.StatusDto.Status.ERROR in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method updateJobExecutionStatus.
@Override
public Future<JobExecution> updateJobExecutionStatus(String jobExecutionId, StatusDto status, OkapiConnectionParams params) {
if (JobExecution.Status.PARENT.name().equals(status.getStatus().name())) {
String errorMessage = "Cannot update JobExecution status to PARENT";
LOGGER.error(errorMessage);
return Future.failedFuture(new BadRequestException(errorMessage));
} else {
return jobExecutionDao.updateBlocking(jobExecutionId, jobExecution -> {
Promise<JobExecution> promise = Promise.promise();
try {
if (JobExecution.Status.PARENT.name().equals(jobExecution.getStatus().name())) {
String message = format("JobExecution %s current status is PARENT and cannot be updated", jobExecutionId);
LOGGER.error(message);
promise.fail(new BadRequestException(message));
} else {
jobExecution.setStatus(JobExecution.Status.fromValue(status.getStatus().name()));
jobExecution.setUiStatus(JobExecution.UiStatus.fromValue(Status.valueOf(status.getStatus().name()).getUiStatus()));
updateJobExecutionIfErrorExist(status, jobExecution);
promise.complete(jobExecution);
}
} catch (Exception e) {
String errorMessage = "Error updating JobExecution with id " + jobExecutionId;
LOGGER.error(errorMessage, e);
promise.fail(errorMessage);
}
return promise.future();
}, params.getTenantId()).compose(jobExecution -> updateSnapshotStatus(jobExecution, params));
}
}
Aggregations