Cleaned up config for Keep Alive settings

This commit is contained in:
Bjarke Berg
2020-03-12 08:28:31 +01:00
parent f446e52d8f
commit e4ff481053
8 changed files with 26 additions and 19 deletions
@@ -21,6 +21,7 @@ namespace Umbraco.Core.Configuration
public IExceptionFilterSettings ExceptionFilterSettings { get; } = new ExceptionFilterSettings();
public ITourSettings TourSettings { get; } = new TourSettings();
public ILoggingSettings LoggingSettings { get; } = new LoggingSettings();
public IKeepAliveSettings KeepAliveSettings { get; } = new KeepAliveSettings();
public IUmbracoSettingsSection UmbracoSettings { get; }
@@ -52,6 +53,7 @@ namespace Umbraco.Core.Configuration
configs.Add<ITourSettings>(() => TourSettings);
configs.Add<ILoggingSettings>(() => LoggingSettings);
configs.Add<IKeepAliveSettings>(() => KeepAliveSettings);
configs.AddCoreConfigs(ioHelper);
return configs;
@@ -0,0 +1,10 @@
using Umbraco.Core.Configuration.UmbracoSettings;
namespace Umbraco.Configuration.Implementations
{
internal class KeepAliveSettings : ConfigurationManagerConfigBase, IKeepAliveSettings
{
public bool DisableKeepAliveTask => UmbracoSettingsSection.KeepAlive.DisableKeepAliveTask;
public string KeepAlivePingUrl => UmbracoSettingsSection.KeepAlive.KeepAlivePingUrl;
}
}
@@ -2,7 +2,7 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class KeepAliveElement : ConfigurationElement, IKeepAliveSection
internal class KeepAliveElement : ConfigurationElement, IKeepAliveSettings
{
[ConfigurationProperty("disableKeepAliveTask", DefaultValue = "false")]
public bool DisableKeepAliveTask => (bool)base["disableKeepAliveTask"];
@@ -32,7 +32,5 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
IRequestHandlerSection IUmbracoSettingsSection.RequestHandler => RequestHandler;
IWebRoutingSection IUmbracoSettingsSection.WebRouting => WebRouting;
IKeepAliveSection IUmbracoSettingsSection.KeepAlive => KeepAlive;
}
}
@@ -1,6 +1,6 @@
namespace Umbraco.Core.Configuration.UmbracoSettings
{
public interface IKeepAliveSection : IUmbracoConfigurationSection
public interface IKeepAliveSettings : IUmbracoConfigurationSection
{
bool DisableKeepAliveTask { get; }
string KeepAlivePingUrl { get; }
@@ -11,7 +11,5 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
IRequestHandlerSection RequestHandler { get; }
IWebRoutingSection WebRouting { get; }
IKeepAliveSection KeepAlive { get; }
}
}
+4 -4
View File
@@ -12,16 +12,16 @@ namespace Umbraco.Web.Scheduling
public class KeepAlive : RecurringTaskBase
{
private readonly IRuntimeState _runtime;
private readonly IKeepAliveSection _keepAliveSection;
private readonly IKeepAliveSettings _keepAliveSettings;
private readonly IProfilingLogger _logger;
private static HttpClient _httpClient;
public KeepAlive(IBackgroundTaskRunner<RecurringTaskBase> runner, int delayMilliseconds, int periodMilliseconds,
IRuntimeState runtime, IKeepAliveSection keepAliveSection, IProfilingLogger logger)
IRuntimeState runtime, IKeepAliveSettings keepAliveSettings, IProfilingLogger logger)
: base(runner, delayMilliseconds, periodMilliseconds)
{
_runtime = runtime;
_keepAliveSection = keepAliveSection;
_keepAliveSettings = keepAliveSettings;
_logger = logger;
if (_httpClient == null)
_httpClient = new HttpClient();
@@ -49,7 +49,7 @@ namespace Umbraco.Web.Scheduling
using (_logger.DebugDuration<KeepAlive>("Keep alive executing", "Keep alive complete"))
{
var keepAlivePingUrl = _keepAliveSection.KeepAlivePingUrl;
var keepAlivePingUrl = _keepAliveSettings.KeepAlivePingUrl;
try
{
if (keepAlivePingUrl.Contains("{umbracoApplicationUrl}"))
@@ -35,11 +35,11 @@ namespace Umbraco.Web.Scheduling
private readonly HealthCheckNotificationMethodCollection _notifications;
private readonly IUmbracoContextFactory _umbracoContextFactory;
private readonly IHealthChecks _healthChecksConfig;
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
private readonly IIOHelper _ioHelper;
private readonly IServerMessenger _serverMessenger;
private readonly IRequestAccessor _requestAccessor;
private readonly ILoggingSettings _loggingSettings;
private readonly IKeepAliveSettings _keepAliveSettings;
private BackgroundTaskRunner<IBackgroundTask> _keepAliveRunner;
private BackgroundTaskRunner<IBackgroundTask> _publishingRunner;
@@ -57,8 +57,8 @@ namespace Umbraco.Web.Scheduling
HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications,
IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger,
IHostingEnvironment hostingEnvironment, IHealthChecks healthChecksConfig,
IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, IServerMessenger serverMessenger, IRequestAccessor requestAccessor,
ILoggingSettings loggingSettings)
IIOHelper ioHelper, IServerMessenger serverMessenger, IRequestAccessor requestAccessor,
ILoggingSettings loggingSettings, IKeepAliveSettings keepAliveSettings)
{
_runtime = runtime;
_contentService = contentService;
@@ -71,11 +71,11 @@ namespace Umbraco.Web.Scheduling
_healthChecks = healthChecks;
_notifications = notifications;
_healthChecksConfig = healthChecksConfig ?? throw new ArgumentNullException(nameof(healthChecksConfig));
_umbracoSettingsSection = umbracoSettingsSection;
_ioHelper = ioHelper;
_serverMessenger = serverMessenger;
_requestAccessor = requestAccessor;
_loggingSettings = loggingSettings;
_keepAliveSettings = keepAliveSettings;
}
public void Initialize()
@@ -114,13 +114,12 @@ namespace Umbraco.Web.Scheduling
LazyInitializer.EnsureInitialized(ref _tasks, ref _started, ref _locker, () =>
{
_logger.Debug<SchedulerComponent>("Initializing the scheduler");
var settings = _umbracoSettingsSection;
var tasks = new List<IBackgroundTask>();
if (settings.KeepAlive.DisableKeepAliveTask == false)
if (_keepAliveSettings.DisableKeepAliveTask == false)
{
tasks.Add(RegisterKeepAlive(settings.KeepAlive));
tasks.Add(RegisterKeepAlive(_keepAliveSettings));
}
tasks.Add(RegisterScheduledPublishing());
@@ -135,11 +134,11 @@ namespace Umbraco.Web.Scheduling
});
}
private IBackgroundTask RegisterKeepAlive(IKeepAliveSection keepAliveSection)
private IBackgroundTask RegisterKeepAlive(IKeepAliveSettings keepAliveSettings)
{
// ping/keepalive
// on all servers
var task = new KeepAlive(_keepAliveRunner, DefaultDelayMilliseconds, FiveMinuteMilliseconds, _runtime, keepAliveSection, _logger);
var task = new KeepAlive(_keepAliveRunner, DefaultDelayMilliseconds, FiveMinuteMilliseconds, _runtime, keepAliveSettings, _logger);
_keepAliveRunner.TryAdd(task);
return task;
}