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); }
private async Task <bool> TryStart([NotNull] IManagedProcess process) { bool success = await process.StartAsync(); if (!success) { process.StartupFailureCount++; } else if (process is IServerProcess serverProcess) { ServiceRegistrar?.Ensure(serverProcess); } return(success); }