Skip to content

Commit 7e75c7c

Browse files
algolia-botmillotpFluf22
committed
feat(clients): cleanup after replaceAllObjects failure [skip-bc] (generated)
algolia/api-clients-automation#3824 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: Thomas Raffray <[email protected]>
1 parent c94506b commit 7e75c7c

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

.github/ISSUE_TEMPLATE/Bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ body:
2727
id: client
2828
attributes:
2929
label: Client
30-
description: Which API are you targetting?
30+
description: Which API are you targeting?
3131
options:
3232
- All
3333
- AB testing

algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -494,37 +494,46 @@ public async Task<ReplaceAllObjectsResponse> ReplaceAllObjectsAsync<T>(string in
494494
var rnd = new Random();
495495
var tmpIndexName = $"{indexName}_tmp_{rnd.Next(100)}";
496496

497-
var copyResponse = await OperationIndexAsync(indexName,
498-
new OperationIndexParams(OperationType.Copy, tmpIndexName)
499-
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
500-
.ConfigureAwait(false);
497+
try
498+
{
499+
var copyResponse = await OperationIndexAsync(indexName,
500+
new OperationIndexParams(OperationType.Copy, tmpIndexName)
501+
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
502+
.ConfigureAwait(false);
501503

502-
var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, true, batchSize,
503-
options, cancellationToken).ConfigureAwait(false);
504+
var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, true, batchSize,
505+
options, cancellationToken).ConfigureAwait(false);
504506

505-
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
506-
.ConfigureAwait(false);
507+
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
508+
.ConfigureAwait(false);
507509

508-
copyResponse = await OperationIndexAsync(indexName,
509-
new OperationIndexParams(OperationType.Copy, tmpIndexName)
510-
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
511-
.ConfigureAwait(false);
512-
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
513-
.ConfigureAwait(false);
510+
copyResponse = await OperationIndexAsync(indexName,
511+
new OperationIndexParams(OperationType.Copy, tmpIndexName)
512+
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
513+
.ConfigureAwait(false);
514+
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
515+
.ConfigureAwait(false);
514516

515-
var moveResponse = await OperationIndexAsync(tmpIndexName,
516-
new OperationIndexParams(OperationType.Move, indexName), options, cancellationToken)
517-
.ConfigureAwait(false);
517+
var moveResponse = await OperationIndexAsync(tmpIndexName,
518+
new OperationIndexParams(OperationType.Move, indexName), options, cancellationToken)
519+
.ConfigureAwait(false);
518520

519-
await WaitForTaskAsync(tmpIndexName, moveResponse.TaskID, requestOptions: options, ct: cancellationToken)
520-
.ConfigureAwait(false);
521+
await WaitForTaskAsync(tmpIndexName, moveResponse.TaskID, requestOptions: options, ct: cancellationToken)
522+
.ConfigureAwait(false);
521523

522-
return new ReplaceAllObjectsResponse
524+
return new ReplaceAllObjectsResponse
525+
{
526+
CopyOperationResponse = copyResponse,
527+
MoveOperationResponse = moveResponse,
528+
BatchResponses = batchResponse
529+
};
530+
}
531+
catch (Exception ex)
523532
{
524-
CopyOperationResponse = copyResponse,
525-
MoveOperationResponse = moveResponse,
526-
BatchResponses = batchResponse
527-
};
533+
await DeleteIndexAsync(tmpIndexName, cancellationToken: cancellationToken).ConfigureAwait(false);
534+
535+
throw ex;
536+
}
528537
}
529538

530539
/// <inheritdoc/>

0 commit comments

Comments
 (0)