use of org.folio.service.EventPublisherService in project mod-circulation-storage by folio-org.
the class ExpirationTool method doRequestExpirationForTenant.
private static Future<Void> doRequestExpirationForTenant(Map<String, String> okapiHeaders, Vertx vertx, String tenant) {
Promise<Void> promise = Promise.promise();
PostgresClient pgClient = PostgresClient.getInstance(vertx, tenant);
List<JsonObject> context = new ArrayList<>();
pgClient.startTx(conn -> getExpiredRequests(conn, vertx, tenant).compose(requests -> closeRequests(conn, vertx, tenant, requests, context)).compose(itemIds -> getOpenRequestsByItemIds(conn, vertx, tenant, itemIds)).compose(requests -> reorderRequests(conn, vertx, tenant, requests)).onComplete(v -> {
if (v.failed()) {
pgClient.rollbackTx(conn, done -> {
log.error("Error in request processing", v.cause());
promise.fail(v.cause());
});
} else {
EventPublisherService eventPublisherService = new EventPublisherService(vertx, okapiHeaders);
context.forEach(p -> eventPublisherService.publishLogRecord(new JsonObject().put(REQUESTS.value(), p), REQUEST_EXPIRED));
pgClient.endTx(conn, done -> promise.complete());
}
}));
return promise.future();
}
Aggregations