From a0da981c299f02fcd90310eda25ec1f9b6c2d36d Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Fri, 23 Apr 2021 09:19:15 +0200 Subject: [PATCH] minor --- .../OpenaireInternalApiController.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OpenaireInternalApiController.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OpenaireInternalApiController.java index 76177e48..d27dd445 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OpenaireInternalApiController.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/OpenaireInternalApiController.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; @@ -41,14 +42,13 @@ public class OpenaireInternalApiController extends AbstractDnetController { synchronized (lastExecution) { if (lastExecution.getStatus() != ImportStatus.RUNNING) { - lastExecution.startNew(); + lastExecution.startNew("Importing dedup events - request from " + req.getRemoteAddr()); new Thread(() -> { try { databaseUtils.importDedupEvents(); lastExecution.complete(); } catch (final Throwable e) { lastExecution.fail(e); - log.error("Error importing conflicts and duplicates", e); } }).start(); } else { @@ -85,7 +85,7 @@ public class OpenaireInternalApiController extends AbstractDnetController { private Long dateStart; private Long dateEnd; private ImportStatus status = ImportStatus.NOT_LAUNCHED; - private String error; + private String message; public String getId() { return id; @@ -119,31 +119,41 @@ public class OpenaireInternalApiController extends AbstractDnetController { this.status = status; } - public String getError() { - return error; + public String getMessage() { + return message; } - public void setError(final String error) { - this.error = error; + public void setMessage(final String message) { + this.message = message; } - public void startNew() { + public void startNew(final String message) { setId("import-" + UUID.randomUUID()); - setDateStart(new Date().getTime()); + setDateStart(System.currentTimeMillis()); setDateEnd(null); setStatus(ImportStatus.RUNNING); - setError(null); + setMessage(message); + log.info(message); } public void complete() { - setDateEnd(new Date().getTime()); + setDateEnd(System.currentTimeMillis()); setStatus(ImportStatus.SUCCESS); + + final long millis = getDateEnd() - getDateStart(); + setMessage(String + .format("Import of dedup events completed in %d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) - + TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)))); + + log.info(getMessage()); + } public void fail(final Throwable e) { setDateEnd(new Date().getTime()); setStatus(ImportStatus.FAILED); - setError(e.getMessage()); + setMessage(e.getMessage()); + log.error("Error importing conflicts and duplicates", e); } }