Skip to content
Snippets Groups Projects
Commit 25a3f9a7 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

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
parent c2929880
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment