Skip to content

Commit af3bd60

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 12b40f5 commit af3bd60

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
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

Sources/Search/Extra/SearchClientExtension.swift

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -559,51 +559,57 @@ public extension SearchClient {
559559
) async throws -> ReplaceAllObjectsResponse {
560560
let tmpIndexName = "\(indexName)_tmp_\(Int.random(in: 1_000_000 ..< 10_000_000))"
561561

562-
var copyOperationResponse = try await operationIndex(
563-
indexName: indexName,
564-
operationIndexParams: OperationIndexParams(
565-
operation: .copy,
566-
destination: tmpIndexName,
567-
scope: [.settings, .rules, .synonyms]
568-
),
569-
requestOptions: requestOptions
570-
)
562+
do {
563+
var copyOperationResponse = try await operationIndex(
564+
indexName: indexName,
565+
operationIndexParams: OperationIndexParams(
566+
operation: .copy,
567+
destination: tmpIndexName,
568+
scope: [.settings, .rules, .synonyms]
569+
),
570+
requestOptions: requestOptions
571+
)
571572

572-
let batchResponses = try await self.chunkedBatch(
573-
indexName: tmpIndexName,
574-
objects: objects,
575-
waitForTasks: true,
576-
batchSize: batchSize,
577-
requestOptions: requestOptions
578-
)
579-
try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID)
573+
let batchResponses = try await self.chunkedBatch(
574+
indexName: tmpIndexName,
575+
objects: objects,
576+
waitForTasks: true,
577+
batchSize: batchSize,
578+
requestOptions: requestOptions
579+
)
580+
try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID)
580581

581-
copyOperationResponse = try await operationIndex(
582-
indexName: indexName,
583-
operationIndexParams: OperationIndexParams(
584-
operation: .copy,
585-
destination: tmpIndexName,
586-
scope: [.settings, .rules, .synonyms]
587-
),
588-
requestOptions: requestOptions
589-
)
590-
try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID)
591-
592-
let moveOperationResponse = try await self.operationIndex(
593-
indexName: tmpIndexName,
594-
operationIndexParams: OperationIndexParams(
595-
operation: .move,
596-
destination: indexName
597-
),
598-
requestOptions: requestOptions
599-
)
600-
try await self.waitForTask(indexName: tmpIndexName, taskID: moveOperationResponse.taskID)
582+
copyOperationResponse = try await operationIndex(
583+
indexName: indexName,
584+
operationIndexParams: OperationIndexParams(
585+
operation: .copy,
586+
destination: tmpIndexName,
587+
scope: [.settings, .rules, .synonyms]
588+
),
589+
requestOptions: requestOptions
590+
)
591+
try await self.waitForTask(indexName: tmpIndexName, taskID: copyOperationResponse.taskID)
601592

602-
return ReplaceAllObjectsResponse(
603-
copyOperationResponse: copyOperationResponse,
604-
batchResponses: batchResponses,
605-
moveOperationResponse: moveOperationResponse
606-
)
593+
let moveOperationResponse = try await self.operationIndex(
594+
indexName: tmpIndexName,
595+
operationIndexParams: OperationIndexParams(
596+
operation: .move,
597+
destination: indexName
598+
),
599+
requestOptions: requestOptions
600+
)
601+
try await self.waitForTask(indexName: tmpIndexName, taskID: moveOperationResponse.taskID)
602+
603+
return ReplaceAllObjectsResponse(
604+
copyOperationResponse: copyOperationResponse,
605+
batchResponses: batchResponses,
606+
moveOperationResponse: moveOperationResponse
607+
)
608+
} catch {
609+
_ = try? await self.deleteIndex(indexName: tmpIndexName)
610+
611+
throw error
612+
}
607613
}
608614

609615
/// Generate a secured API key

0 commit comments

Comments
 (0)