// register current server (throttled).
        private void RegisterServer(UmbracoRequestEventArgs e)
        {
            lock (_locko) // ensure we trigger only once
            {
                var secondsSinceLastUpdate = DateTime.Now.Subtract(_lastUpdated).TotalSeconds;
                if (secondsSinceLastUpdate < _registrar.Options.ThrottleSeconds)
                {
                    return;
                }
                _lastUpdated = DateTime.Now;
            }

            var svc = e.UmbracoContext.Application.Services.ServerRegistrationService;

            // because
            // - ApplicationContext.UmbracoApplicationUrl is initialized by UmbracoModule in BeginRequest
            // - RegisterServer is called on UmbracoModule.RouteAttempt which is triggered in ProcessRequest
            // we are safe, UmbracoApplicationUrl has been initialized
            var serverAddress = e.UmbracoContext.Application.UmbracoApplicationUrl;

            try
            {
                svc.TouchServer(serverAddress, svc.CurrentServerIdentity, _registrar.Options.StaleServerTimeout);
            }
            catch (Exception ex)
            {
                LogHelper.Error <ServerRegistrationEventHandler>("Failed to update server record in database.", ex);
            }
        }
Пример #2
0
 private void OnEndRequest(UmbracoRequestEventArgs args)
 {
     if (EndRequest != null)
     {
         EndRequest(this, args);
     }
 }
        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());
            });
        }
Пример #4
0
        void UmbracoModule_EndRequest(object sender, UmbracoRequestEventArgs args)
        {
            CheckUrlTrackerInstalled();

            if (_execute)
            {
                UrlTrackerDo("EndRequest", context: args.HttpContext.ApplicationInstance.Context);
            }
        }
Пример #5
0
        void context_EndRequest(object sender, UmbracoRequestEventArgs e)
        {
            CheckUrlTrackerInstalled();

            if (_execute)
            {
                UrlTrackerDo("EndRequest");
            }
        }
        private void RegisterBackgroundTasks(UmbracoRequestEventArgs e)
        {
            //remove handler, we're done
            UmbracoModule.RouteAttempt -= UmbracoModuleRouteAttempt;

            //only perform this one time ever
            LazyInitializer.EnsureInitialized(ref _task, ref _started, ref _lock, () =>
            {
                var serverAddress = e.UmbracoContext.Application.UmbracoApplicationUrl;
                var svc           = e.UmbracoContext.Application.Services.ServerRegistrationService;

                var task = new TouchServerTask(_backgroundTaskRunner,
                                               15000,                                      //delay before first execution
                                               _registrar.Options.RecurringSeconds * 1000, //amount of ms between executions
                                               svc, _registrar, serverAddress);

                //Perform the rest async, we don't want to block the startup sequence
                // this will just reoccur on a background thread
                _backgroundTaskRunner.TryAdd(task);

                return(task);
            });
        }
 /// <summary>
 /// Triggers the EndRequest event.
 /// </summary>
 internal static void OnEndRequest(object sender, UmbracoRequestEventArgs args)
 {
     EndRequest?.Invoke(sender, args);
 }
Пример #8
0
 void UmbracoModule_EndRequest(object sender, UmbracoRequestEventArgs e)
 {
     FlushBatch();
 }
Пример #9
0
 private void UmbracoModule_EndRequest(object sender, UmbracoRequestEventArgs e)
 {
     // will clear the batch - will remain in HttpContext though - that's ok
     FlushBatch();
 }
Пример #10
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());
            });
        }