Пример #1
0
        public override Task PerformExecuteAsync(object state)
        {
            if (_runtimeState.Level != RuntimeLevel.Run)
            {
                return(Task.CompletedTask);
            }

            // If the IServerRoleAccessor has been changed away from ElectedServerRoleAccessor this task no longer makes sense,
            // since all it's used for is to allow the ElectedServerRoleAccessor
            // to figure out what role a given server has, so we just stop this task.
            if (_serverRoleAccessor is not ElectedServerRoleAccessor)
            {
                return(StopAsync(CancellationToken.None));
            }

            var serverAddress = _hostingEnvironment.ApplicationMainUrl?.ToString();

            if (serverAddress.IsNullOrWhiteSpace())
            {
                _logger.LogWarning("No umbracoApplicationUrl for service (yet), skip.");
                return(Task.CompletedTask);
            }

            try
            {
                _serverRegistrationService.TouchServer(serverAddress, _globalSettings.DatabaseServerRegistrar.StaleServerTimeout);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to update server record in database.");
            }

            return(Task.CompletedTask);
        }
Пример #2
0
        public override Task PerformExecuteAsync(object state)
        {
            if (_runtimeState.Level != RuntimeLevel.Run)
            {
                return(Task.CompletedTask);
            }

            var serverAddress = _hostingEnvironment.ApplicationMainUrl?.ToString();

            if (serverAddress.IsNullOrWhiteSpace())
            {
                _logger.LogWarning("No umbracoApplicationUrl for service (yet), skip.");
                return(Task.CompletedTask);
            }

            try
            {
                _serverRegistrationService.TouchServer(serverAddress, _globalSettings.DatabaseServerRegistrar.StaleServerTimeout);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to update server record in database.");
            }

            return(Task.CompletedTask);
        }
 /// <summary>
 /// Runs the background task.
 /// </summary>
 /// <returns>A value indicating whether to repeat the task.</returns>
 public override bool PerformRun()
 {
     try
     {
         // TouchServer uses a proper unit of work etc underneath so even in a
         // background task it is safe to call it without dealing with any scope
         _svc.TouchServer(_serverAddress, _svc.CurrentServerIdentity, _registrar.Options.StaleServerTimeout);
         return(true); // repeat
     }
     catch (Exception ex)
     {
         _logger.Error <DatabaseServerRegistrarAndMessengerComponent>(ex, "Failed to update server record in database.");
         return(false); // probably stop if we have an error
     }
 }
        private void EnsureServerRegistered()
        {
            IServerRegistrationService serverRegistrationService = GetRequiredService <IServerRegistrationService>();

            serverRegistrationService.TouchServer("http://localhost", TimeSpan.FromMinutes(10));
        }