Files
Umbraco-CMS/src/Umbraco.Core/Extensions/HealthCheckSettingsExtensions.cs
Andy Butland 98c9124735 Refactored logic for calculating the first run time for a recurring hosted service. (#12828)
* Refactors the logic for calculating the first run time for a recurring task for easier re-use by similar hostservices.

* Renamed method to match wider usage.
2022-08-12 10:14:15 +01:00

28 lines
1.1 KiB
C#

using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
namespace Umbraco.Extensions;
// TODO (V12): Remove this class that's no longer used.
[Obsolete("Please use RecurringHostedServiceBase.GetDelay(). This class is no longer used within Umbraco and will be removed in V12.")]
public static class HealthCheckSettingsExtensions
{
public static TimeSpan GetNotificationDelay(this HealthChecksSettings settings, ICronTabParser cronTabParser, 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;
}
// Otherwise start at scheduled time according to cron expression, unless within the default delay period.
DateTime firstRunOccurance = cronTabParser.GetNextOccurrence(firstRunTime, now);
TimeSpan delay = firstRunOccurance - now;
return delay < defaultDelay
? defaultDelay
: delay;
}
}