From 93eb697cd6f84feb6a316821ea06f4a1ff0373fc Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Tue, 31 Dec 2024 14:39:49 +0000 Subject: [PATCH] feat(clients): cleanup after replaceAllObjects failure [skip-bc] (generated) https://github.com/algolia/api-clients-automation/pull/3824 Co-authored-by: algolia-bot Co-authored-by: Pierre Millot Co-authored-by: Thomas Raffray --- .github/ISSUE_TEMPLATE/Bug_report.yml | 2 +- packages/client-search/src/searchClient.ts | 92 ++++++++++++---------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Bug_report.yml b/.github/ISSUE_TEMPLATE/Bug_report.yml index ecf2dfdbd..d01e1b390 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.yml +++ b/.github/ISSUE_TEMPLATE/Bug_report.yml @@ -27,7 +27,7 @@ body: id: client attributes: label: Client - description: Which API are you targetting? + description: Which API are you targeting? options: - All - AB testing diff --git a/packages/client-search/src/searchClient.ts b/packages/client-search/src/searchClient.ts index e25494c56..19c25ce35 100644 --- a/packages/client-search/src/searchClient.ts +++ b/packages/client-search/src/searchClient.ts @@ -642,57 +642,63 @@ export function createSearchClient({ const randomSuffix = Math.floor(Math.random() * 1000000) + 100000; const tmpIndexName = `${indexName}_tmp_${randomSuffix}`; - let copyOperationResponse = await this.operationIndex( - { - indexName, - operationIndexParams: { - operation: 'copy', - destination: tmpIndexName, - scope: ['settings', 'rules', 'synonyms'], + try { + let copyOperationResponse = await this.operationIndex( + { + indexName, + operationIndexParams: { + operation: 'copy', + destination: tmpIndexName, + scope: ['settings', 'rules', 'synonyms'], + }, }, - }, - requestOptions, - ); + requestOptions, + ); - const batchResponses = await this.chunkedBatch( - { indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, - requestOptions, - ); + const batchResponses = await this.chunkedBatch( + { indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, + requestOptions, + ); - await this.waitForTask({ - indexName: tmpIndexName, - taskID: copyOperationResponse.taskID, - }); + await this.waitForTask({ + indexName: tmpIndexName, + taskID: copyOperationResponse.taskID, + }); - copyOperationResponse = await this.operationIndex( - { - indexName, - operationIndexParams: { - operation: 'copy', - destination: tmpIndexName, - scope: ['settings', 'rules', 'synonyms'], + copyOperationResponse = await this.operationIndex( + { + indexName, + operationIndexParams: { + operation: 'copy', + destination: tmpIndexName, + scope: ['settings', 'rules', 'synonyms'], + }, }, - }, - requestOptions, - ); - await this.waitForTask({ - indexName: tmpIndexName, - taskID: copyOperationResponse.taskID, - }); + requestOptions, + ); + await this.waitForTask({ + indexName: tmpIndexName, + taskID: copyOperationResponse.taskID, + }); - const moveOperationResponse = await this.operationIndex( - { + const moveOperationResponse = await this.operationIndex( + { + indexName: tmpIndexName, + operationIndexParams: { operation: 'move', destination: indexName }, + }, + requestOptions, + ); + await this.waitForTask({ indexName: tmpIndexName, - operationIndexParams: { operation: 'move', destination: indexName }, - }, - requestOptions, - ); - await this.waitForTask({ - indexName: tmpIndexName, - taskID: moveOperationResponse.taskID, - }); + taskID: moveOperationResponse.taskID, + }); - return { copyOperationResponse, batchResponses, moveOperationResponse }; + return { copyOperationResponse, batchResponses, moveOperationResponse }; + } catch (error) { + await this.deleteIndex({ indexName: tmpIndexName }); + + throw error; + } }, async indexExists({ indexName }: GetSettingsProps): Promise {