Sort out weird time in DB clean task

This commit is contained in:
Risto Lahtela 2021-03-19 16:38:57 +02:00
parent aa1a35f794
commit ebd6330ec1

View File

@ -136,14 +136,14 @@ public class DBCleanTask extends TaskSystem.Task {
Integer id = serverInfo.getServer().getId().orElse(1); Integer id = serverInfo.getServer().getId().orElse(1);
double distributor = id * 1.0 / biggestId; // 0 < distributor <= 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. // -40 seconds to start first at 20 seconds if only one server is present and period is 1 minute.
long startAfter = (long) (distributor * distributingOverTime) - 40L; long startAfterMs = (long) (distributor * distributingOverTimeMs) - TimeUnit.SECONDS.toMillis(40L);
long delay = TimeAmount.toTicks(startAfter, TimeUnit.MILLISECONDS); long delayTicks = TimeAmount.toTicks(startAfterMs, TimeUnit.MILLISECONDS);
long period = TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS); long periodTicks = TimeAmount.toTicks(config.get(TimeSettings.CLEAN_DATABASE_PERIOD), TimeUnit.MILLISECONDS);
runnableFactory.create(taskToRegister).runTaskTimerAsynchronously(delay, period); runnableFactory.create(taskToRegister).runTaskTimerAsynchronously(delayTicks, periodTicks);
}).runTaskAsynchronously(); }).runTaskAsynchronously();
} }