Skip to content

Commit

Permalink
Merge pull request #162 from CSCfi/indexer-improvements2
Browse files Browse the repository at this point in the history
Increase cronjob allowed execution time. Add logging to index switch
  • Loading branch information
sarkikos authored Nov 8, 2024
2 parents c0c589d + 36ded2f commit b4dd24d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions aspnetcore/src/ElasticService/ElasticSearchIndexService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task IndexAsync(string indexName, List<object> 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);
}
Expand All @@ -43,8 +43,9 @@ public async Task IndexChunkAsync(string indexToCreate, List<object> 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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion aspnetcore/src/ElasticService/IElasticSearchIndexService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public interface IElasticSearchIndexService
/// <param name="indexName"></param>
/// <param name="indexToCreate"></param>
/// <param name="indexToDelete"></param>
/// <param name="modelTypeName"></param>
/// <returns></returns>
Task SwitchIndexes(string indexName, string indexToCreate, string indexToDelete);
Task SwitchIndexes(string indexName, string indexToCreate, string indexToDelete, string modelTypeName);
}
2 changes: 1 addition & 1 deletion aspnetcore/src/Indexer/Indexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4dd24d

Please sign in to comment.