From 404718caa3ee405665a69818b42ecbbba5fcbaa9 Mon Sep 17 00:00:00 2001 From: Tom Hollis <57675191+tomrhollis@users.noreply.github.com> Date: Wed, 14 Oct 2020 13:16:24 -0600 Subject: [PATCH 1/4] Combine callbacks to try to fix timer issues --- src/Program.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index b12ead1..759a8f0 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -291,11 +291,8 @@ public VellumHost(string[] args) else Console.WriteLine("Skipping this backup because no players were online since the last one was taken..."); } - }; - if (RunConfig.Backups.EnableSchedule && RunConfig.Backups.Schedule.Length > 0) - { - backupIntervalTimer.Elapsed += (object sender, ElapsedEventArgs e) => + if (RunConfig.Backups.EnableSchedule && RunConfig.Backups.Schedule.Length > 0) { // Check which entry is up next TimeSpan nextSpan = TimeSpan.MaxValue; @@ -333,8 +330,8 @@ public VellumHost(string[] args) Console.WriteLine($"Next scheduled backup is at {(DateTime.Now + nextSpan).ToShortTimeString()} (in {nextSpan.Days} days, {nextSpan.Hours} hours, {nextSpan.Minutes} minutes and {nextSpan.Seconds} seconds)"); backupIntervalTimer.Interval = nextSpan.TotalMilliseconds; CallHook((byte)Hook.BACKUP_SCHEDULED, new HookEventArgs() { Attachment = nextSpan }); - }; - } + } + }; backupIntervalTimer.Start(); From a08a800d7d9ec260ad7a012396bc6cb11107d7e2 Mon Sep 17 00:00:00 2001 From: Tom Hollis <57675191+tomrhollis@users.noreply.github.com> Date: Thu, 15 Oct 2020 10:50:58 -0600 Subject: [PATCH 2/4] parse & set rewritten to see if that fixes --- src/Program.cs | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 759a8f0..d56273e 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -296,34 +296,23 @@ public VellumHost(string[] args) { // Check which entry is up next TimeSpan nextSpan = TimeSpan.MaxValue; + DateTime backupTime = DateTime.Now; foreach (string clockTime in RunConfig.Backups.Schedule) { - // Parse & validate entry - // Match match = Regex.Match(clockTime, @"^\s*(\d{1,2})\s*:\s*(\d{1,2})\s*([aApP][mM])"); // 12h format - Match match = Regex.Match(clockTime, @"^\s*(\d{1,2})\s*:\s*(\d{1,2})\s*$"); // 24h format - - bool valid = false; - int hour, minute; - - if (match.Groups.Count == 3) + try { - hour = Convert.ToInt32(match.Groups[1].Value); - minute = Convert.ToInt32(match.Groups[2].Value); - - if ((hour >= 0 && hour <= 23) && (minute >= 0 && minute <= 59)) - { - valid = true; - - TimeSpan span = new TimeSpan((hour == 0 ? 24 : hour) - DateTime.Now.Hour, minute - DateTime.Now.Minute, 0 - DateTime.Now.Second); - - if (span.TotalSeconds > 0 && span < nextSpan) - nextSpan = span; - } + backupTime = DateTime.Parse(clockTime); } - - if (!valid) + catch (FormatException) + { Console.WriteLine($"Invalid schedule entry \"{clockTime}\" in \"{_configPath}\"!"); + continue; + } + + if (backupTime < DateTime.Now) backupTime.AddDays(1); + TimeSpan span = backupTime.Subtract(DateTime.Now); + if (span.TotalSeconds > 0 && span < nextSpan) nextSpan = span; } // Set the new interval From 278819ac66a694be44f61bb8fb349117de3004a9 Mon Sep 17 00:00:00 2001 From: Tom Hollis <57675191+tomrhollis@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:00:56 -0600 Subject: [PATCH 3/4] missed assignment --- src/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index d56273e..2e797db 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -309,8 +309,7 @@ public VellumHost(string[] args) Console.WriteLine($"Invalid schedule entry \"{clockTime}\" in \"{_configPath}\"!"); continue; } - - if (backupTime < DateTime.Now) backupTime.AddDays(1); + if (backupTime < DateTime.Now) backupTime = backupTime.AddDays(1); TimeSpan span = backupTime.Subtract(DateTime.Now); if (span.TotalSeconds > 0 && span < nextSpan) nextSpan = span; } From a011f7cd8a28d29aff5f1197052bb2422bc3e57a Mon Sep 17 00:00:00 2001 From: Tom Hollis <57675191+tomrhollis@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:13:45 -0600 Subject: [PATCH 4/4] add 2 second buffer to work around randomly short timers --- src/Program.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 2e797db..8608417 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -293,7 +293,7 @@ public VellumHost(string[] args) } if (RunConfig.Backups.EnableSchedule && RunConfig.Backups.Schedule.Length > 0) - { + { // Check which entry is up next TimeSpan nextSpan = TimeSpan.MaxValue; DateTime backupTime = DateTime.Now; @@ -309,9 +309,10 @@ public VellumHost(string[] args) Console.WriteLine($"Invalid schedule entry \"{clockTime}\" in \"{_configPath}\"!"); continue; } - if (backupTime < DateTime.Now) backupTime = backupTime.AddDays(1); + // 2 second buffer to fix this timer sometimes jumping the gun by a few hundred milliseconds -TH + if (backupTime < DateTime.Now.AddSeconds(2)) backupTime = backupTime.AddDays(1); TimeSpan span = backupTime.Subtract(DateTime.Now); - if (span.TotalSeconds > 0 && span < nextSpan) nextSpan = span; + if (span.TotalSeconds > 2 && span < nextSpan) nextSpan = span; } // Set the new interval