Changed configuration of first run time for health check notifier from a time string to a cron expression.

This commit is contained in:
Andy Butland
2020-10-31 22:49:12 +01:00
parent bdb8f34da3
commit a0ce44c9fc
10 changed files with 42 additions and 112 deletions

View File

@@ -1,25 +0,0 @@
using System;
namespace Umbraco.Core.Configuration.Models.Extensions
{
public static class HealthCheckSettingsExtensions
{
public static TimeSpan GetNotificationDelay(this HealthChecksSettings settings, DateTime now, TimeSpan defaultDelay)
{
// If first run time not set, start with just small delay after application start.
var firstRunTime = settings.Notification.FirstRunTime;
if (string.IsNullOrEmpty(firstRunTime))
{
return defaultDelay;
}
else
{
// Otherwise start at scheduled time.
var delay = TimeSpan.FromMinutes(now.PeriodicMinutesFrom(firstRunTime));
return (delay < defaultDelay)
? defaultDelay
: delay;
}
}
}
}

View File

@@ -42,11 +42,11 @@ namespace Umbraco.Core.Configuration.Models.Validation
return true;
}
public bool ValidateOptionalTime(string configPath, string value, out string message)
public bool ValidateOptionalCronTab(string configPath, string value, out string message)
{
if (!string.IsNullOrEmpty(value) && !value.IsValidTimeSpan())
if (!string.IsNullOrEmpty(value) && !value.IsValidCronTab())
{
message = $"Configuration entry {configPath} contains an invalid time value.";
message = $"Configuration entry {configPath} contains an invalid cron expression.";
return false;
}

View File

@@ -16,7 +16,7 @@ namespace Umbraco.Core.Configuration.Models.Validation
private bool ValidateNotificationFirstRunTime(string value, out string message)
{
return ValidateOptionalTime($"{Constants.Configuration.ConfigHealthChecks}:{nameof(HealthChecksSettings.Notification)}:{nameof(HealthChecksSettings.Notification.FirstRunTime)}", value, out message);
return ValidateOptionalCronTab($"{Constants.Configuration.ConfigHealthChecks}:{nameof(HealthChecksSettings.Notification)}:{nameof(HealthChecksSettings.Notification.FirstRunTime)}", value, out message);
}
}
}