From 0253aa223d02fa0289e79f6b00f1c932dcf59ad6 Mon Sep 17 00:00:00 2001 From: Owen Li Date: Mon, 16 Oct 2017 10:56:11 -0400 Subject: [PATCH] Fix LogFileCompressor scheduling Since: I1e665848cd7cd5f93628db97c0af17900d243f9d initial delay for the scheduled task was not being calculated correctly, leading to the task initially being run much later than expected. Change-Id: I88dc9b10785b15f46eb21463a48e49d4416cd651 --- .../com/google/gerrit/pgm/util/LogFileCompressor.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/LogFileCompressor.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/LogFileCompressor.java index 666d03c596..919136ea84 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/LogFileCompressor.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/util/LogFileCompressor.java @@ -29,8 +29,9 @@ import java.io.OutputStream; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; -import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.temporal.ChronoUnit; import java.util.concurrent.Future; import java.util.zip.GZIPOutputStream; import org.slf4j.Logger; @@ -62,8 +63,9 @@ public class LogFileCompressor implements Runnable { //compress log once and then schedule compression every day at 11:00pm queue.getDefaultQueue().execute(compressor); ZoneId zone = ZoneId.systemDefault(); - LocalDate now = LocalDate.now(zone); - long milliSecondsUntil11pm = now.atStartOfDay(zone).plusHours(23).toInstant().toEpochMilli(); + LocalDateTime now = LocalDateTime.now(zone); + long milliSecondsUntil11pm = + now.until(now.withHour(23).withMinute(0).withSecond(0).withNano(0), ChronoUnit.MILLIS); @SuppressWarnings("unused") Future possiblyIgnoredError = queue