Port 7.7 - WIP
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Components;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.HealthCheck;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Scheduling
|
||||
@@ -22,35 +25,45 @@ namespace Umbraco.Web.Scheduling
|
||||
internal sealed class SchedulerComponent : UmbracoComponentBase, IUmbracoCoreComponent
|
||||
{
|
||||
private IRuntimeState _runtime;
|
||||
private IUserService _userService;
|
||||
private IContentService _contentService;
|
||||
private IAuditService _auditService;
|
||||
private ILogger _logger;
|
||||
private ProfilingLogger _proflog;
|
||||
private IScopeProvider _scopeProvider;
|
||||
private HealthCheckCollection _healthChecks;
|
||||
private HealthCheckNotificationMethodCollection _notifications;
|
||||
|
||||
private BackgroundTaskRunner<IBackgroundTask> _keepAliveRunner;
|
||||
private BackgroundTaskRunner<IBackgroundTask> _publishingRunner;
|
||||
private BackgroundTaskRunner<IBackgroundTask> _tasksRunner;
|
||||
private BackgroundTaskRunner<IBackgroundTask> _scrubberRunner;
|
||||
private BackgroundTaskRunner<IBackgroundTask> _healthCheckRunner;
|
||||
|
||||
private bool _started;
|
||||
private object _locker = new object();
|
||||
private IBackgroundTask[] _tasks;
|
||||
|
||||
public void Initialize(IRuntimeState runtime, IUserService userService, IAuditService auditService, IScopeProvider scopeProvider, ILogger logger, ProfilingLogger proflog)
|
||||
public void Initialize(IRuntimeState runtime,
|
||||
IContentService contentService, IAuditService auditService,
|
||||
HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications,
|
||||
IScopeProvider scopeProvider, ILogger logger, ProfilingLogger proflog)
|
||||
{
|
||||
_runtime = runtime;
|
||||
_userService = userService;
|
||||
_contentService = contentService;
|
||||
_auditService = auditService;
|
||||
_scopeProvider = scopeProvider;
|
||||
_logger = logger;
|
||||
_proflog = proflog;
|
||||
|
||||
_healthChecks = healthChecks;
|
||||
_notifications = notifications;
|
||||
|
||||
// backgrounds runners are web aware, if the app domain dies, these tasks will wind down correctly
|
||||
_keepAliveRunner = new BackgroundTaskRunner<IBackgroundTask>("KeepAlive", logger);
|
||||
_publishingRunner = new BackgroundTaskRunner<IBackgroundTask>("ScheduledPublishing", logger);
|
||||
_tasksRunner = new BackgroundTaskRunner<IBackgroundTask>("ScheduledTasks", logger);
|
||||
_scrubberRunner = new BackgroundTaskRunner<IBackgroundTask>("LogScrubber", logger);
|
||||
_healthCheckRunner = new BackgroundTaskRunner<IBackgroundTask>("HealthCheckNotifier", logger);
|
||||
|
||||
// we will start the whole process when a successful request is made
|
||||
UmbracoModule.RouteAttempt += UmbracoModuleRouteAttempt;
|
||||
@@ -62,12 +75,12 @@ namespace Umbraco.Web.Scheduling
|
||||
{
|
||||
case EnsureRoutableOutcome.IsRoutable:
|
||||
case EnsureRoutableOutcome.NotDocumentRequest:
|
||||
RegisterBackgroundTasks(e);
|
||||
RegisterBackgroundTasks();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterBackgroundTasks(UmbracoRequestEventArgs e)
|
||||
private void RegisterBackgroundTasks()
|
||||
{
|
||||
// remove handler, we're done
|
||||
UmbracoModule.RouteAttempt -= UmbracoModuleRouteAttempt;
|
||||
@@ -77,30 +90,78 @@ namespace Umbraco.Web.Scheduling
|
||||
_logger.Debug<SchedulerComponent>(() => "Initializing the scheduler");
|
||||
var settings = UmbracoConfig.For.UmbracoSettings();
|
||||
|
||||
var tasks = new List<IBackgroundTask>
|
||||
{
|
||||
new KeepAlive(_keepAliveRunner, 60000, 300000, _runtime, _logger, _proflog),
|
||||
new ScheduledPublishing(_publishingRunner, 60000, 60000, _runtime, _userService, _scopeProvider, _logger, _proflog),
|
||||
new ScheduledTasks(_tasksRunner, 60000, 60000, _runtime, settings, _logger, _proflog),
|
||||
new LogScrubber(_scrubberRunner, 60000, LogScrubber.GetLogScrubbingInterval(settings, _logger), _runtime, _auditService, settings, _scopeProvider, _logger, _proflog)
|
||||
};
|
||||
var tasks = new List<IBackgroundTask>();
|
||||
|
||||
// ping/keepalive
|
||||
// on all servers
|
||||
_keepAliveRunner.TryAdd(tasks[0]);
|
||||
tasks.Add(RegisterKeepAlive());
|
||||
tasks.Add(RegisterScheduledPublishing());
|
||||
tasks.Add(RegisterTaskRunner(settings));
|
||||
tasks.Add(RegisterLogScrubber(settings));
|
||||
|
||||
// scheduled publishing/unpublishing
|
||||
// install on all, will only run on non-slaves servers
|
||||
_publishingRunner.TryAdd(tasks[1]);
|
||||
|
||||
_tasksRunner.TryAdd(tasks[2]);
|
||||
|
||||
// log scrubbing
|
||||
// install on all, will only run on non-slaves servers
|
||||
_scrubberRunner.TryAdd(tasks[3]);
|
||||
var healthCheckConfig = UmbracoConfig.For.HealthCheck();
|
||||
if (healthCheckConfig.NotificationSettings.Enabled)
|
||||
tasks.Add(RegisterHealthCheckNotifier(healthCheckConfig, _healthChecks, _notifications, _logger, _proflog));
|
||||
|
||||
return tasks.ToArray();
|
||||
});
|
||||
}
|
||||
|
||||
private IBackgroundTask RegisterKeepAlive()
|
||||
{
|
||||
// ping/keepalive
|
||||
// on all servers
|
||||
var task = new KeepAlive(_keepAliveRunner, 60000, 300000, _runtime, _logger, _proflog);
|
||||
_keepAliveRunner.TryAdd(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
private IBackgroundTask RegisterScheduledPublishing()
|
||||
{
|
||||
// scheduled publishing/unpublishing
|
||||
// install on all, will only run on non-slaves servers
|
||||
var task = new ScheduledPublishing(_publishingRunner, 60000, 60000, _runtime, _contentService, _logger);
|
||||
_publishingRunner.TryAdd(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
private IBackgroundTask RegisterTaskRunner(IUmbracoSettingsSection settings)
|
||||
{
|
||||
var task = new ScheduledTasks(_tasksRunner, 60000, 60000, _runtime, settings, _logger, _proflog);
|
||||
_tasksRunner.TryAdd(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
private IBackgroundTask RegisterHealthCheckNotifier(IHealthChecks healthCheckConfig,
|
||||
HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications,
|
||||
ILogger logger, ProfilingLogger proflog)
|
||||
{
|
||||
// If first run time not set, start with just small delay after application start
|
||||
int delayInMilliseconds;
|
||||
if (string.IsNullOrEmpty(healthCheckConfig.NotificationSettings.FirstRunTime))
|
||||
{
|
||||
delayInMilliseconds = 60000;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise start at scheduled time
|
||||
delayInMilliseconds = DateTime.Now.PeriodicMinutesFrom(healthCheckConfig.NotificationSettings.FirstRunTime) * 60 * 1000;
|
||||
if (delayInMilliseconds < 60000)
|
||||
{
|
||||
delayInMilliseconds = 60000;
|
||||
}
|
||||
}
|
||||
|
||||
var periodInMilliseconds = healthCheckConfig.NotificationSettings.PeriodInHours * 60 * 60 * 1000;
|
||||
var task = new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, healthChecks, notifications, _runtime, logger, proflog);
|
||||
return task;
|
||||
}
|
||||
|
||||
private IBackgroundTask RegisterLogScrubber(IUmbracoSettingsSection settings)
|
||||
{
|
||||
// log scrubbing
|
||||
// install on all, will only run on non-slaves servers
|
||||
var task = new LogScrubber(_scrubberRunner, 60000, LogScrubber.GetLogScrubbingInterval(settings, _logger), _runtime, _auditService, settings, _scopeProvider, _logger, _proflog);
|
||||
_scrubberRunner.TryAdd(task);
|
||||
return task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user