diff --git a/ATXCommon/TimeUtils.cs b/ATXCommon/TimeUtils.cs index 04cc8fa2817d8ea8504fd237c452e3e474ada3e6..8a27393df67448dfb35237c3e500ff39c3f87799 100644 --- a/ATXCommon/TimeUtils.cs +++ b/ATXCommon/TimeUtils.cs @@ -11,5 +11,23 @@ namespace ATXCommon public static string Timestamp() { return DateTime.Now.ToString("yyyy-MM-dd__HH-mm-ss"); } + + /// <summary> + /// Calculate the time delta since the given date in minutes. + /// </summary> + /// <param name="refDate">The reference DateTime to check.</param> + /// <returns>The number of minutes between the reference date and now.</returns> + public static int MinutesSince(DateTime refDate) { + return (int)(DateTime.Now - refDate).TotalMinutes; + } + + /// <summary> + /// Calculate the time delta since the given date in seconds. + /// </summary> + /// <param name="refDate">The reference DateTime to check.</param> + /// <returns>The number of seconds between the reference date and now.</returns> + public static int SecondsSince(DateTime refDate) { + return (int)(DateTime.Now - refDate).TotalSeconds; + } } } diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index 243548466484013d1303c4f2357705b8e57dfcd7..5e816cd3676f9a64f59f8f9ff9fbb19be2866998 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -489,8 +489,7 @@ namespace AutoTx SendLowSpaceMail(SystemChecks.CheckFreeDiskSpace(_config.SpaceMonitoring)); UpdateServiceState(); - var delta = (int)(DateTime.Now - _lastUserDirCheck).TotalSeconds; - if (delta >= 120) + if (TimeUtils.SecondsSince(_lastUserDirCheck) >= 120) CreateIncomingDirectories(); // tasks depending on the service state: @@ -934,7 +933,7 @@ namespace AutoTx if (string.IsNullOrEmpty(report)) return ""; report = "Expired folders in grace location:\n" + report; - var delta = (int)(DateTime.Now - _status.LastGraceNotification).TotalMinutes; + var delta = TimeUtils.MinutesSince(_status.LastGraceNotification); report += "\nTime since last grace notification: " + delta + "\n"; if (delta >= _config.GraceNotificationDelta) { SendAdminEmail(report, "Grace location cleanup required."); diff --git a/AutoTx/Email.cs b/AutoTx/Email.cs index 584d54605cfb474044a7fb70dd3c5b66e751bc01..96d435a7baaa202920631fe6f879977c390ba4d7 100644 --- a/AutoTx/Email.cs +++ b/AutoTx/Email.cs @@ -80,7 +80,7 @@ namespace AutoTx if (_config.SendAdminNotification == false) return; - var delta = (int)(DateTime.Now - _status.LastAdminNotification).TotalMinutes; + var delta = TimeUtils.MinutesSince(_status.LastAdminNotification); if (delta < _config.AdminNotificationDelta) { Log.Debug("Suppressed admin email, interval too short ({0} vs. {1}):\n\n{2}\n{3}", delta, _config.AdminNotificationDelta, subject, body); @@ -109,9 +109,11 @@ namespace AutoTx if (string.IsNullOrWhiteSpace(spaceDetails)) return; - var delta = (int)(DateTime.Now - _status.LastStorageNotification).TotalMinutes; - if (delta < _config.StorageNotificationDelta) + var delta = TimeUtils.MinutesSince(_status.LastStorageNotification); + if (delta < _config.StorageNotificationDelta) { + Log.Trace("Only {0} minutes since last low-space-notification, skipping.", delta); return; + } Log.Warn("WARNING: {0}", spaceDetails); _status.LastStorageNotification = DateTime.Now;