示例#1
0
        private async Task <bool> TryRecycle([NotNull] IManagedProcess managedProcess,
                                             [CanBeNull] ServiceRegistrar serviceRegistrar)
        {
            _logger.LogInformation("The process {process} is due for recycling.", managedProcess);

            int?ongoingRequests = await managedProcess.GetOngoingRequestCountAsync();

            if (ongoingRequests > 0)
            {
                _logger.LogWarning(
                    "Process recycling is delayed due to one or more ongoing requests being processed.");
                return(false);
            }

            // TODO: Send shutdown signal (that sets unhealthy = true and then waits another few seconds before shutting down to avoid races)

            await ManagedProcessUtils.ShutDownAsync(managedProcess, serviceRegistrar,
                                                    TimeSpan.Zero);

            // However, the advantage of killing is that we can re-start it straight away:
            bool success = await managedProcess.StartAsync();

            if (success &&
                managedProcess is IServerProcess serverProcess)
            {
                serviceRegistrar?.Ensure(serverProcess);
            }

            return(success);
        }
示例#2
0
        private async Task <bool> CareForUnhealthy(IManagedProcess process)
        {
            // TODO: Consider adding a new process while still shutting down, but only if ephemeral ports are used

            _logger.LogInformation("(Re-)starting process with status 'not serving': {process}",
                                   process);

            string message =
                await ManagedProcessUtils.ShutDownAsync(process, ServiceRegistrar,
                                                        MemberMaxShutdownTime);

            if (!string.IsNullOrEmpty(message))
            {
                _logger.LogDebug(message);
            }

            if (process.StartupFailureCount > MemberMaxStartupRetries)
            {
                _logger.LogWarning("Startup retries have been exceeded. Not starting {process}",
                                   process);

                return(false);
            }

            return(await TryStart(process));
        }