From ebd6330ec101f921643da648db6041936ca1d7b9 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Fri, 19 Mar 2021 16:38:57 +0200 Subject: [PATCH] Sort out weird time in DB clean task --- .../djrapitops/plan/storage/upkeep/DBCleanTask.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/upkeep/DBCleanTask.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/upkeep/DBCleanTask.java index 6b34432d6..312ed8f46 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/upkeep/DBCleanTask.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/upkeep/DBCleanTask.java @@ -136,14 +136,14 @@ public class DBCleanTask extends TaskSystem.Task { Integer id = serverInfo.getServer().getId().orElse(1); double distributor = id * 1.0 / biggestId; // 0 < distributor <= 1 - long distributingOverTime = config.get(TimeSettings.CLEAN_DATABASE_PERIOD); + long distributingOverTimeMs = config.get(TimeSettings.CLEAN_DATABASE_PERIOD); - // -40 seconds to start first at 20 seconds if only one server is present. - long startAfter = (long) (distributor * distributingOverTime) - 40L; + // -40 seconds to start first at 20 seconds if only one server is present and period is 1 minute. + long startAfterMs = (long) (distributor * distributingOverTimeMs) - TimeUnit.SECONDS.toMillis(40L); - long delay = TimeAmount.toTicks(startAfter, TimeUnit.MILLISECONDS); - long period = TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS); - runnableFactory.create(taskToRegister).runTaskTimerAsynchronously(delay, period); + long delayTicks = TimeAmount.toTicks(startAfterMs, TimeUnit.MILLISECONDS); + long periodTicks = TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS); + runnableFactory.create(taskToRegister).runTaskTimerAsynchronously(delayTicks, periodTicks); }).runTaskAsynchronously(); }