public static void Run([TimerTrigger("%CronExpression%")] TimerInfo timerInfo, ExecutionContext context, ILogger log) { var configuration = GetConfiguration(context); var section = configuration.GetSection("Curator"); var settings = section.Get <CuratorSettings>(); Parallel.ForEach( settings.Entries, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount * 2 }, entry => { log.LogInformation($"Name = {entry.Name}, Endpoint = {entry.Endpoint}"); var client = ElasticsearchHelper.CreateElasticClient(new Uri(entry.Endpoint), settings.RequestTimeout); foreach (var indexEntry in entry.IndexEntries) { IEnumerable <CatIndicesRecord> indices = null; try { indices = ElasticsearchHelper.GetOutOfDateIndices(client, indexEntry, log); } catch (Exception e) { log.LogError(e, $"!!> Error while fetching out-of-date indices (requestTimeout?): {e.Message}"); continue; } foreach (var idx in indices) { if (!settings.WithDryRun) { log.LogInformation($"--> Deleting index '{idx.Index}' (Status = {idx.Status}, DocsCount = {idx.DocsCount}, PrimaryStoreSize = {idx.PrimaryStoreSize}, StoreSize = {idx.StoreSize})"); try { client.DeleteIndex(idx.Index); } catch (Exception e) { log.LogError(e, $"!!> Error while deleting index '{idx.Index}': {e.Message}"); } } else { log.LogInformation($"--> [DRY-RUN] Deleting index '{idx.Index}' (Status = {idx.Status}, DocsCount = {idx.DocsCount}, PrimaryStoreSize = {idx.PrimaryStoreSize}, StoreSize = {idx.StoreSize})"); } } } }); }