From e67b9e224f6b846efae065bcad065bd889b55c5a Mon Sep 17 00:00:00 2001 From: "Ray J. Greenwell" Date: Fri, 23 Aug 2013 13:28:02 -0700 Subject: [PATCH] Tweaks to the way the reboot manager computes scheduled reboots. - Previously if you scheduled a reboot for 5am every day, but the server came up at 3am, it would schedule the reboot for 5am the next day. Subtract a day if the current time is before the rebootHour. - When skipping weekends always push the time out rather than pulling it in. Questionable, but so was the previous behavior. If you set it to reboot daily but skip weekends, it would not skip weekends. --- .../presents/server/RebootManager.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/threerings/presents/server/RebootManager.java b/core/src/main/java/com/threerings/presents/server/RebootManager.java index 0855bd9f9..acf686e19 100644 --- a/core/src/main/java/com/threerings/presents/server/RebootManager.java +++ b/core/src/main/java/com/threerings/presents/server/RebootManager.java @@ -28,7 +28,6 @@ import com.samskivert.util.HashIntMap; import com.samskivert.util.Interval; import com.samskivert.util.ObserverList; import com.samskivert.util.StringUtil; -import com.samskivert.util.Calendars.Builder; import com.threerings.util.MessageBundle; @@ -80,26 +79,24 @@ public abstract class RebootManager { // maybe schedule an automatic reboot based on our configuration int freq = getDayFrequency(); - if (freq == -1) { + int hour = getRebootHour(); + if (freq <= 0) { return false; } - Builder cal = Calendars.now().zeroTime().addHours(getRebootHour()).addDays(freq); + Calendars.Builder cal = Calendars.now(); + int curHour = cal.get(Calendar.HOUR_OF_DAY); + cal = cal.zeroTime().addHours(hour).addDays((curHour < hour) ? (freq - 1) : freq); // maybe avoid weekends if (getSkipWeekends()) { - int dow = cal.get(Calendar.DAY_OF_WEEK); - switch (dow) { + switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.SATURDAY: - if (freq > 1) { - cal.addDays(-1); - } + cal.addDays(2); break; case Calendar.SUNDAY: - if (freq > 2) { - cal.addDays(-2); - } + cal.addDays(1); break; } }