use of org.kie.kogito.jobs.service.exception.JobServiceException in project kogito-apps by kiegroup.
the class ReactiveMessagingEventConsumer method handleEvent.
private Uni<Void> handleEvent(Message<JobCloudEvent<?>> message, CreateProcessInstanceJobRequestEvent event) {
return Uni.createFrom().completionStage(jobRepository.get(event.getData().getId())).flatMap(existingJob -> {
if (existingJob == null || existingJob.getStatus() == JobStatus.SCHEDULED) {
return Uni.createFrom().publisher(scheduler.schedule(ScheduledJobAdapter.to(ScheduledJob.builder().job(event.getData()).build())));
} else {
LOGGER.info("A Job in status: {} already exists for the job id: {}, no processing will be done fot the event: {}.", existingJob.getStatus(), existingJob.getId(), event);
return Uni.createFrom().item(existingJob);
}
}).onItem().transformToUni(createdJob -> {
if (createdJob == null) {
// The scheduler halted the stream processing by emitting no values, an error was produced.
return Uni.createFrom().failure(new JobServiceException("An internal scheduler error was produced during Job scheduling"));
} else {
return Uni.createFrom().completionStage(message.ack());
}
}).onFailure().recoverWithUni(throwable -> {
String msg = String.format("An error was produced during Job scheduling for the event: %s", event);
LOGGER.error(msg, throwable);
return Uni.createFrom().completionStage(message.nack(new JobServiceException("An error was produced during Job scheduling: " + throwable.getMessage(), throwable)));
});
}
Aggregations