Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase cronjob allowed execution time. Add logging to index switch #162

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading