From 4c76542f54fa517ac167e8fcc67b18f57086dbf6 Mon Sep 17 00:00:00 2001 From: fabianArbeit Date: Wed, 6 Nov 2024 10:00:35 +0100 Subject: [PATCH] - also log after a certain amount of time if processing is slow --- FabianUtil.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/FabianUtil.java b/FabianUtil.java index 2b75423..cf8487a 100644 --- a/FabianUtil.java +++ b/FabianUtil.java @@ -87,15 +87,27 @@ public class FabianUtil { public void logIf() { - if (counter.remainder(logDistance).signum() == 0) { + if (counter.remainder(logDistance).signum() == 0 || isBored()) { log(); } } + private boolean isBored() { + ZonedDateTime time = lastLoggedAt == null ? startTime : lastLoggedAt; + return time.until(ZonedDateTime.now(), ChronoUnit.SECONDS) >= timeLogDistance; + } + + public void log() { Duration timePassed = getTimePassed(); System.out.println(counter + " Stück erledigt. " + formatDuration(timePassed) + " vergangen."); + updateLastLoggedAt(); + } + + + protected void updateLastLoggedAt() { + lastLoggedAt = ZonedDateTime.now(); } @@ -163,6 +175,7 @@ public class FabianUtil { String counterPrint = total.compareTo(BigDecimal.TEN) >= 0 ? formatNumber(counter) : counter.toString(); System.out.println(counterPrint + " Stück von " + total + " (" + PERCENTAGE_FORMAT.format(percentage) + " %) erledigt. " + formatDuration(timePassed) + " vergangen" + remainingTimePart + "."); + updateLastLoggedAt(); } }