private void RegisterBackgroundTasks(UmbracoRequestEventArgs e)
        {
            //remove handler, we're done
            UmbracoModule.RouteAttempt -= UmbracoModuleRouteAttempt;

            LazyInitializer.EnsureInitialized(ref _tasks, ref _started, ref _locker, () =>
            {
                LogHelper.Debug <Scheduler>(() => "Initializing the scheduler");
                var settings = UmbracoConfig.For.UmbracoSettings();

                var tasks = new List <IBackgroundTask>
                {
                    new KeepAlive(_keepAliveRunner, 60000, 300000, e.UmbracoContext.Application),
                    new ScheduledPublishing(_publishingRunner, 60000, 60000, e.UmbracoContext.Application, settings),
                    new ScheduledTasks(_tasksRunner, 60000, 60000, e.UmbracoContext.Application, settings),
                    new LogScrubber(_scrubberRunner, 60000, LogScrubber.GetLogScrubbingInterval(settings), e.UmbracoContext.Application, settings)
                };

                // ping/keepalive
                // on all servers
                _keepAliveRunner.TryAdd(tasks[0]);

                // 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]);

                return(tasks.ToArray());
            });
        }
Exemplo n.º 2
0
        private IBackgroundTask RegisterLogScrubber(IUmbracoSettingsSection settings)
        {
            // log scrubbing
            // install on all, will only run on non-replica servers
            var task = new LogScrubber(_scrubberRunner, DefaultDelayMilliseconds, LogScrubber.GetLogScrubbingInterval(settings, _logger), _runtime, _auditService, settings, _scopeProvider, _logger);

            _scrubberRunner.TryAdd(task);
            return(task);
        }
Exemplo n.º 3
0
        private void RegisterBackgroundTasks(UmbracoRequestEventArgs e)
        {
            //remove handler, we're done
            UmbracoModule.RouteAttempt -= UmbracoModuleRouteAttempt;

            LazyInitializer.EnsureInitialized(ref _tasks, ref _started, ref _locker, () =>
            {
                LogHelper.Debug <Scheduler>(() => "Initializing the scheduler");
                var settings = UmbracoConfig.For.UmbracoSettings();

                var healthCheckConfig = UmbracoConfig.For.HealthCheck();

                const int delayMilliseconds = 60000;
                var tasks = new List <IBackgroundTask>
                {
                    new KeepAlive(_keepAliveRunner, delayMilliseconds, 300000, e.UmbracoContext.Application),
                    new ScheduledPublishing(_publishingRunner, delayMilliseconds, 60000, e.UmbracoContext.Application, settings),
                    new ScheduledTasks(_tasksRunner, delayMilliseconds, 60000, e.UmbracoContext.Application, settings),
                    new LogScrubber(_scrubberRunner, delayMilliseconds, LogScrubber.GetLogScrubbingInterval(settings), e.UmbracoContext.Application, settings),
                };

                if (healthCheckConfig.NotificationSettings.Enabled)
                {
                    // If first run time not set, start with just small delay after application start
                    int delayInMilliseconds;
                    if (string.IsNullOrEmpty(healthCheckConfig.NotificationSettings.FirstRunTime))
                    {
                        delayInMilliseconds = delayMilliseconds;
                    }
                    else
                    {
                        // Otherwise start at scheduled time
                        delayInMilliseconds = DateTime.Now.PeriodicMinutesFrom(healthCheckConfig.NotificationSettings.FirstRunTime) * 60 * 1000;
                        if (delayInMilliseconds < delayMilliseconds)
                        {
                            delayInMilliseconds = delayMilliseconds;
                        }
                    }

                    var periodInMilliseconds = healthCheckConfig.NotificationSettings.PeriodInHours * 60 * 60 * 1000;
                    tasks.Add(new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, e.UmbracoContext.Application));
                }

                // ping/keepalive
                // on all servers
                _keepAliveRunner.TryAdd(tasks[0]);

                // 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]);

                if (healthCheckConfig.NotificationSettings.Enabled)
                {
                    _healthCheckRunner.TryAdd(tasks[4]);
                }

                return(tasks.ToArray());
            });
        }
Exemplo n.º 4
0
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            if (umbracoApplication.Context == null)
            {
                return;
            }

            //subscribe to app init so we can subsribe to the application events
            UmbracoApplicationBase.ApplicationInit += (sender, args) =>
            {
                var app = (HttpApplication)sender;

                //subscribe to the end of a successful request (a handler actually executed)
                app.PostRequestHandlerExecute += (o, eventArgs) =>
                {
                    if (_started == false)
                    {
                        lock (Locker)
                        {
                            if (_started == false)
                            {
                                _started = true;
                                LogHelper.Debug <Scheduler>(() => "Initializing the scheduler");

                                // backgrounds runners are web aware, if the app domain dies, these tasks will wind down correctly
                                _keepAliveRunner  = new BackgroundTaskRunner <IBackgroundTask>("KeepAlive", applicationContext.ProfilingLogger.Logger);
                                _publishingRunner = new BackgroundTaskRunner <IBackgroundTask>("ScheduledPublishing", applicationContext.ProfilingLogger.Logger);
                                _tasksRunner      = new BackgroundTaskRunner <IBackgroundTask>("ScheduledTasks", applicationContext.ProfilingLogger.Logger);
                                _scrubberRunner   = new BackgroundTaskRunner <IBackgroundTask>("LogScrubber", applicationContext.ProfilingLogger.Logger);

                                var settings = UmbracoConfig.For.UmbracoSettings();

                                // ping/keepalive
                                // on all servers
                                _keepAliveRunner.Add(new KeepAlive(_keepAliveRunner, 60000, 300000, applicationContext));

                                // scheduled publishing/unpublishing
                                // install on all, will only run on non-slaves servers
                                _publishingRunner.Add(new ScheduledPublishing(_publishingRunner, 60000, 60000, applicationContext, settings));
                                _tasksRunner.Add(new ScheduledTasks(_tasksRunner, 60000, 60000, applicationContext, settings));

                                // log scrubbing
                                // install on all, will only run on non-slaves servers
                                _scrubberRunner.Add(new LogScrubber(_scrubberRunner, 60000, LogScrubber.GetLogScrubbingInterval(settings), applicationContext, settings));
                            }
                        }
                    }
                };
            };
        }