Schedule log file compression at 11:00pm
Log file compression was happening every 24 hours but the exact time was depending on when Gerrit was started. First execution was 1 hour after Gerrit is started and then every 24 hours. This behavior could confuse Gerrit administrators because it looks like log compression is random. Since logs are rotated upon first logging event after midnight, compressing logs at 11:00pm should give enough time for all logs to rotate, worst case they will be compressed the day after. Change-Id: I81d4df8c57996a483378f6107cd6db561fa0d670
This commit is contained in:
parent
9a662a0755
commit
2f46364950
@ -16,6 +16,7 @@ BASE_JETTY_DEPS = [
|
||||
'//lib/guice:guice-assistedinject',
|
||||
'//lib/guice:guice-servlet',
|
||||
'//lib/jgit/org.eclipse.jgit:jgit',
|
||||
'//lib/joda:joda-time',
|
||||
'//lib/log:api',
|
||||
'//lib/log:log4j',
|
||||
]
|
||||
|
@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.pgm.util;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.HOURS;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
@ -23,6 +24,8 @@ import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.git.WorkQueue;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -59,7 +62,14 @@ public class LogFileCompressor implements Runnable {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
queue.getDefaultQueue().scheduleAtFixedRate(compressor, 1, 24, HOURS);
|
||||
//compress log once and then schedule compression every day at 11:00pm
|
||||
queue.getDefaultQueue().execute(compressor);
|
||||
DateTime now = DateTime.now();
|
||||
long milliSecondsUntil11am =
|
||||
new Duration(now, now.withTimeAtStartOfDay().plusHours(23))
|
||||
.getMillis();
|
||||
queue.getDefaultQueue().scheduleAtFixedRate(compressor,
|
||||
milliSecondsUntil11am, HOURS.toMillis(24), MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user