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

Split GraceLocationSummary into separate methods for summary and email.

This allows us to re-use the summary method in other tools like the tray
application.
parent 27a30d6a
Branches
Tags
No related merge requests found
......@@ -122,6 +122,31 @@ namespace ATXCommon
return collection;
}
/// <summary>
/// Generate a report on expired folders in the grace location.
///
/// Check all user-directories in the grace location for subdirectories whose timestamp
/// (the directory name) exceeds the configured grace period and generate a summary
/// containing the age and size of those directories.
/// </summary>
/// <param name="graceLocation">The location to scan for expired folders.</param>
/// <param name="threshold">The number of days used as expiration threshold.</param>
public static string GraceLocationSummary(DirectoryInfo graceLocation, int threshold) {
var expired = ExpiredDirs(graceLocation, threshold);
var report = "";
foreach (var userdir in expired.Keys) {
report += "\n - user '" + userdir + "'\n";
foreach (var subdir in expired[userdir]) {
report += string.Format(" - {0} [age: {2} days, size: {1}]\n",
subdir.Item1, Conv.BytesToString(subdir.Item2), subdir.Item3);
}
}
if (string.IsNullOrEmpty(report))
return "";
return "Expired folders in grace location:\n" + report;
}
/// <summary>
/// Check if a given directory is empty. If a marker file is set in the config a
/// file with this name will be created inside the given directory and will be
......
......@@ -300,7 +300,7 @@ namespace AutoTx
msg += "\n------ Grace location status (threshold: " + _config.GracePeriod + ") ------\n";
try {
var tmp = GraceLocationSummary(_config.GracePeriod);
var tmp = SendGraceLocationSummary(_config.GracePeriod);
if (string.IsNullOrEmpty(tmp)) {
msg += " -- NO EXPIRED folders in grace location! --\n";
} else {
......@@ -721,7 +721,7 @@ namespace AutoTx
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(GraceLocationSummary(_config.GracePeriod));
Log.Debug(SendGraceLocationSummary(_config.GracePeriod));
return;
}
errMsg = "unable to move " + sourceDirectory.FullName;
......@@ -761,39 +761,6 @@ namespace AutoTx
_lastUserDirCheck = DateTime.Now;
}
/// <summary>
/// Generate a report on expired folders in the grace location.
///
/// Check all user-directories in the grace location for subdirectories whose timestamp
/// (the directory name) exceeds the configured grace period and generate a summary
/// containing the age and size of those directories. The summary will be sent to the admin
/// if the configured GraceNotificationDelta has passed since the last email.
/// </summary>
/// <param name="threshold">The number of days used as expiration threshold.</param>
public string GraceLocationSummary(int threshold) {
var doneDir = new DirectoryInfo(Path.Combine(_managedPath, "DONE"));
var expired = FsUtils.ExpiredDirs(doneDir, threshold);
var report = "";
foreach (var userdir in expired.Keys) {
report += "\n - user '" + userdir + "'\n";
foreach (var subdir in expired[userdir]) {
report += string.Format(" - {0} [age: {2} days, size: {1}]\n",
subdir.Item1, Conv.BytesToString(subdir.Item2), subdir.Item3);
}
}
if (string.IsNullOrEmpty(report))
return "";
report = "Expired folders in grace location:\n" + report;
var delta = TimeUtils.MinutesSince(_status.LastGraceNotification);
report += "\nTime since last grace notification: " + delta + "\n";
if (delta >= _config.GraceNotificationDelta) {
SendAdminEmail(report, "Grace location cleanup required.");
_status.LastGraceNotification = DateTime.Now;
report += "\nNotification sent to AdminEmailAdress.\n";
}
return report;
}
#endregion
}
......
......@@ -218,5 +218,29 @@ namespace AutoTx
SendAdminEmail(msg);
}
}
/// <summary>
/// Send a report on expired folders in the grace location if applicable.
///
/// Create a summary of expired folders and send it to the admin address
/// if the configured GraceNotificationDelta has passed since the last email.
/// </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(Path.Combine(_managedPath, "DONE")), threshold);
if (string.IsNullOrEmpty(report))
return "";
var delta = TimeUtils.MinutesSince(_status.LastGraceNotification);
report += "\nTime since last grace notification: " + delta + "\n";
if (delta < _config.GraceNotificationDelta)
return report;
_status.LastGraceNotification = DateTime.Now;
SendAdminEmail(report, "Grace location cleanup required.");
return report + "\nNotification sent to AdminEmailAdress.\n";
}
}
}
\ 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