diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs index c944a5a120fd6a4d32af2155aaccb86a08722c1c..e7a65ee8c14676d9147d63f7cc105aff7164cca2 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 91fdf611e6d4495ecaf205afd421612336d786b8..59aeeb23f05a76eb914ea6e22299e30b93adf5b2 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