private static void StartComponentHost(IComponentHost componentHost, IAsynchronousLogger logger, CancellationTokenSource cancellationTokenSource) { componentHost.StartAsync(new StaticComponentHostConfigurationProvider(new List<ComponentConfiguration> { new ComponentConfiguration { ComponentIdentity = HostableComponentIdentities.LogQueueProcessor, Instances = 1, RestartEvaluator = (ex, retryCount) => RestartHandler(ex, retryCount, logger, HostableComponentIdentities.LogQueueProcessor).Result } }), cancellationTokenSource); }
private static async Task<bool> RestartHandler(Exception ex, int retryCount, IAsynchronousLogger logger, IComponentIdentity component) { try { bool doDelay = retryCount % 5 == 0; if (doDelay) { await logger.WarningAsync( $"Error occurred in component {component.FullyQualifiedName}. Restarting in 30 seconds.", ex); await Task.Delay(TimeSpan.FromSeconds(30)); } else { await logger.WarningAsync($"Error occurred in component {component.FullyQualifiedName}. Restarting immediately.", ex); } } catch (Exception) { // swallow any issues } return true; }