From 25a3f9a7a75c07c05889f5bcb586bf9603e43026 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Mon, 29 Apr 2019 15:32:22 +0200 Subject: [PATCH] Convert SendGraceLocationSummary() from string to bool, w/o parameters Having the threshold as a parameter is not necessary as the new StorageStatus object has this property built-in already. Returning the generated message is also not required any more as it can easily be retrieved from that instance as well. Relates to #20 --- ATxService/AutoTx.cs | 5 ++--- ATxService/Email.cs | 31 +++++++++++++++++-------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs index c944a5a..e7a65ee 100644 --- a/ATxService/AutoTx.cs +++ b/ATxService/AutoTx.cs @@ -915,9 +915,8 @@ namespace ATxService sourceDirectory.Delete(); if (sourceDirectory.Parent != null) sourceDirectory.Parent.Delete(); - // check age and size of existing folders in the grace location after - // a transfer has completed, trigger a notification if necessary: - Log.Debug(SendGraceLocationSummary(_config.GracePeriod)); + // check grace location and trigger a notification if necessary: + SendGraceLocationSummary(); return; } errMsg = "unable to move " + sourceDirectory.FullName; diff --git a/ATxService/Email.cs b/ATxService/Email.cs index 91fdf61..59aeeb2 100644 --- a/ATxService/Email.cs +++ b/ATxService/Email.cs @@ -212,23 +212,26 @@ namespace ATxService /// GraceNotificationDelta has passed since the last email. The report will also contain a /// summary of free disk space for all configured drives. /// </summary> - /// <param name="threshold">The number of days used as expiration threshold.</param> - /// <returns>The summary report, empty if no expired folders exist.</returns> - private string SendGraceLocationSummary(int threshold) { - var report = FsUtils.GraceLocationSummary( - new DirectoryInfo(_config.DonePath), threshold); - if (string.IsNullOrEmpty(report)) - return ""; - - report += $"\n{SystemChecks.CheckFreeDiskSpace(_config.SpaceMonitoring)}" + - "\nTime since last grace notification: " + - $"{TimeUtils.HumanSince(_status.LastGraceNotification)}\n"; - if (TimeUtils.MinutesSince(_status.LastGraceNotification) < _config.GraceNotificationDelta) - return report; + /// <returns>True if a report was sent, false otherwise (includes situations where there + /// are expired directories but the report has not been sent via email as the grace + /// notification delta hasn't expired yet, the report will still be logged then).</returns> + private bool SendGraceLocationSummary() { + if (_storage.ExpiredDirsCount == 0) + return false; + + var report = _storage.Summary() + + "\nTime since last grace notification: " + + $"{TimeUtils.HumanSince(_status.LastGraceNotification)}\n"; + + if (TimeUtils.MinutesSince(_status.LastGraceNotification) < _config.GraceNotificationDelta) { + Log.Debug(report); + return false; + } _status.LastGraceNotification = DateTime.Now; SendAdminEmail(report, "grace location summary"); - return report + "\nNotification sent to AdminEmailAdress.\n"; + Log.Debug("Notification sent to AdminEmailAdress."); + return true; } } } \ No newline at end of file -- GitLab