From 36ded2fd7c6aa4237146de51e33c83e51e0250bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Sa=CC=88rkikoski?= Date: Fri, 8 Nov 2024 09:20:16 +0200 Subject: [PATCH] Increase cronjob max allowed execution time. Add logging to index switching. --- .../indexer/rahti2/template-indexer-cronjob-devel.yml | 2 +- .../indexer/rahti2/template-indexer-cronjob-production.yml | 2 +- .../indexer/rahti2/template-indexer-cronjob-qa.yml | 2 +- aspnetcore/src/ElasticService/ElasticSearchIndexService.cs | 6 ++++-- aspnetcore/src/ElasticService/IElasticSearchIndexService.cs | 3 ++- aspnetcore/src/Indexer/Indexer.cs | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-devel.yml b/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-devel.yml index 63feb83..908a4a7 100644 --- a/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-devel.yml +++ b/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-devel.yml @@ -30,7 +30,7 @@ objects: failedJobsHistoryLimit: 2 jobTemplate: spec: - activeDeadlineSeconds: 2400 # Can run for 40 minutes + activeDeadlineSeconds: 5400 # Can run for 90 minutes template: spec: restartPolicy: Never diff --git a/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-production.yml b/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-production.yml index 84c9733..0dc112e 100644 --- a/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-production.yml +++ b/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-production.yml @@ -30,7 +30,7 @@ objects: failedJobsHistoryLimit: 2 jobTemplate: spec: - activeDeadlineSeconds: 2400 # Can run for 40 minutes + activeDeadlineSeconds: 5400 # Can run for 90 minutes template: spec: restartPolicy: Never diff --git a/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-qa.yml b/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-qa.yml index 5d124ae..d3ff438 100644 --- a/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-qa.yml +++ b/aspnetcore/openshift/indexer/rahti2/template-indexer-cronjob-qa.yml @@ -30,7 +30,7 @@ objects: failedJobsHistoryLimit: 2 jobTemplate: spec: - activeDeadlineSeconds: 2400 # Can run for 40 minutes + activeDeadlineSeconds: 5400 # Can run for 90 minutes template: spec: restartPolicy: Never diff --git a/aspnetcore/src/ElasticService/ElasticSearchIndexService.cs b/aspnetcore/src/ElasticService/ElasticSearchIndexService.cs index d1d0d01..0ff095f 100644 --- a/aspnetcore/src/ElasticService/ElasticSearchIndexService.cs +++ b/aspnetcore/src/ElasticService/ElasticSearchIndexService.cs @@ -32,7 +32,7 @@ public async Task IndexAsync(string indexName, List entities, Type model await IndexEntities(indexToCreate, entities, modelType); // Switch indexes - await SwitchIndexes(indexName, indexToCreate, indexToDelete); + await SwitchIndexes(indexName, indexToCreate, indexToDelete, modelType.Name); _logger.LogDebug("{EntityType:l}: Indexing to {IndexName:l} complete", modelType.Name, indexName); } @@ -43,8 +43,9 @@ public async Task IndexChunkAsync(string indexToCreate, List entities, T await IndexEntities(indexToCreate, entities, modelType); } - public async Task SwitchIndexes(string indexName, string indexToCreate, string indexToDelete) + public async Task SwitchIndexes(string indexName, string indexToCreate, string indexToDelete, string modelTypeName) { + _logger.LogInformation($"{modelTypeName}: Switch indexes start: indexName={indexName}, indexToCreate={indexToCreate}, indexToDelete={indexToDelete}"); // Wait for new index to be operational. await _elasticClient.Cluster .HealthAsync(selector: s => s @@ -61,6 +62,7 @@ await _elasticClient.Indices.BulkAliasAsync(r => r // Delete the old index if it exists. await _elasticClient.Indices.DeleteAsync(indexToDelete, d => d.RequestConfiguration(x => x.AllowedStatusCodes(404))); + _logger.LogInformation($"{modelTypeName}: Switch indexes complete"); } public async Task<(string indexToCreate, string indexToDelete)> GetIndexNames(string indexName) diff --git a/aspnetcore/src/ElasticService/IElasticSearchIndexService.cs b/aspnetcore/src/ElasticService/IElasticSearchIndexService.cs index 960b848..f949344 100644 --- a/aspnetcore/src/ElasticService/IElasticSearchIndexService.cs +++ b/aspnetcore/src/ElasticService/IElasticSearchIndexService.cs @@ -48,6 +48,7 @@ public interface IElasticSearchIndexService /// /// /// + /// /// - Task SwitchIndexes(string indexName, string indexToCreate, string indexToDelete); + Task SwitchIndexes(string indexName, string indexToCreate, string indexToDelete, string modelTypeName); } \ No newline at end of file diff --git a/aspnetcore/src/Indexer/Indexer.cs b/aspnetcore/src/Indexer/Indexer.cs index 5c8ed9c..7da2a99 100644 --- a/aspnetcore/src/Indexer/Indexer.cs +++ b/aspnetcore/src/Indexer/Indexer.cs @@ -177,7 +177,7 @@ private async Task IndexEntities(string indexName, IIndexRepository repository, } while (numOfResults >= takeAmount - 1); // Activate new index and delete old - await _indexService.SwitchIndexes(indexName, indexToCreate, indexToDelete); + await _indexService.SwitchIndexes(indexName, indexToCreate, indexToDelete, type.Name); _logger.LogInformation("{EntityType:l}: Recreated index {IndexName:l}, {ElasticsearchDocumentCount} documents", type.Name, indexName, processedCount); } else