public async Task Does_Not_Execute_When_Role_Accessor_Is_Not_Elected()
        {
            TouchServerTask sut = CreateTouchServerTask(useElection: false);
            await sut.PerformExecuteAsync(null);

            VerifyServerNotTouched();
        }
        public async Task Executes_And_Touches_Server()
        {
            TouchServerTask sut = CreateTouchServerTask();
            await sut.PerformExecuteAsync(null);

            VerifyServerTouched();
        }
        public async Task Does_Not_Execute_When_Application_Url_Is_Not_Available()
        {
            TouchServerTask sut = CreateTouchServerTask(applicationUrl: string.Empty);
            await sut.PerformExecuteAsync(null);

            VerifyServerNotTouched();
        }
        public async Task Does_Not_Execute_When_Runtime_State_Is_Not_Run(RuntimeLevel runtimeLevel)
        {
            TouchServerTask sut = CreateTouchServerTask(runtimeLevel: runtimeLevel);
            await sut.PerformExecuteAsync(null);

            VerifyServerNotTouched();
        }
        private IBackgroundTask RegisterTouchServer(IServerRegistrationService registrationService, string serverAddress)
        {
            var task = new TouchServerTask(_touchTaskRunner,
                                           15000,                                      //delay before first execution
                                           _registrar.Options.RecurringSeconds * 1000, //amount of ms between executions
                                           registrationService, _registrar, serverAddress, _logger);

            _touchTaskRunner.TryAdd(task);
            return(task);
        }
        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);
            });
        }