use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.
the class JobExecutionDaoImpl method mapRowToProgress.
private Progress mapRowToProgress(Row row) {
Integer processedCount = row.getInteger(CURRENTLY_PROCESSED_FIELD);
Integer total = row.getInteger(TOTAL_FIELD);
if (processedCount == null) {
processedCount = row.getInteger(PROGRESS_CURRENT_FIELD);
}
if (total == null) {
total = row.getInteger(PROGRESS_TOTAL_FIELD);
}
return new Progress().withJobExecutionId(row.getValue(ID_FIELD).toString()).withCurrent(processedCount).withTotal(total);
}
use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.
the class MetadataProviderJobExecutionAPITest method shouldReturnSortedJobExecutionsByTotalProgressOnGet.
@Test
public void shouldReturnSortedJobExecutionsByTotalProgressOnGet() {
List<JobExecution> createdJobExecution = constructAndPostInitJobExecutionRqDto(4).getJobExecutions();
List<JobExecution> childJobsToUpdate = createdJobExecution.stream().filter(jobExecution -> jobExecution.getSubordinationType().equals(CHILD)).collect(Collectors.toList());
for (int i = 0; i < childJobsToUpdate.size(); i++) {
putJobExecution(createdJobExecution.get(i).withProgress(new Progress().withTotal(i * 5)));
}
// We do not expect to get JobExecution with subordinationType=PARENT_MULTIPLE
int expectedJobExecutionsNumber = childJobsToUpdate.size();
JobExecutionDtoCollection jobExecutionCollection = RestAssured.given().spec(spec).when().queryParam("sortBy", "progress_total,desc").get(GET_JOB_EXECUTIONS_PATH).then().statusCode(HttpStatus.SC_OK).extract().response().body().as(JobExecutionDtoCollection.class);
List<JobExecutionDto> jobExecutions = jobExecutionCollection.getJobExecutions();
Assert.assertEquals(expectedJobExecutionsNumber, jobExecutions.size());
assertThat(jobExecutions.get(0).getProgress().getTotal(), greaterThan(jobExecutions.get(1).getProgress().getTotal()));
assertThat(jobExecutions.get(1).getProgress().getTotal(), greaterThan(jobExecutions.get(2).getProgress().getTotal()));
assertThat(jobExecutions.get(2).getProgress().getTotal(), greaterThan(jobExecutions.get(3).getProgress().getTotal()));
}
use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.
the class RecordProcessedEventHandlingServiceImpl method handle.
@Override
public Future<Boolean> handle(String eventContent, OkapiConnectionParams params) {
Promise<Boolean> promise = Promise.promise();
DataImportEventPayload dataImportEventPayload;
try {
dataImportEventPayload = new ObjectMapper().readValue(eventContent, DataImportEventPayload.class);
} catch (IOException e) {
LOGGER.error("Failed to read eventContent {}", eventContent, e);
promise.fail(e);
return promise.future();
}
String jobExecutionId = dataImportEventPayload.getJobExecutionId();
try {
DataImportEventTypes eventType = DataImportEventTypes.valueOf(dataImportEventPayload.getEventType());
jobExecutionProgressService.updateJobExecutionProgress(jobExecutionId, progress -> changeProgressAccordingToEventType(progress, eventType), params.getTenantId()).compose(updatedProgress -> updateJobExecutionIfAllRecordsProcessed(jobExecutionId, updatedProgress, params)).onComplete(ar -> {
if (ar.failed()) {
LOGGER.error("Failed to handle {} event", eventType, ar.cause());
updateJobStatusToError(jobExecutionId, params).onComplete(statusAr -> promise.fail(ar.cause()));
} else {
promise.complete(true);
}
});
} catch (Exception e) {
LOGGER.error("Failed to handle event {}", eventContent, e);
updateJobStatusToError(jobExecutionId, params);
promise.fail(e);
}
return promise.future();
}
use of org.folio.rest.jaxrs.model.Progress in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldProcessLastChunkOfRawRecords.
@Test
public void shouldProcessLastChunkOfRawRecords(TestContext testContext) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
jobExec.setRunBy(new RunBy().withFirstName("DIKU").withLastName("ADMINISTRATOR"));
jobExec.setProgress(new Progress().withCurrent(1000).withTotal(1000));
jobExec.setStartedDate(new Date());
WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
Async async = testContext.async();
RestAssured.given().spec(spec).body(jobExec).when().put(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).log().all();
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
async.complete();
rawRecordsDto.getRecordsMetadata().setLast(true);
async = testContext.async();
RestAssured.given().spec(spec).body(rawRecordsDto.withId(UUID.randomUUID().toString())).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK);
async.complete();
}
Aggregations