Skip to content

Commit

Permalink
feat(clients): cleanup after replaceAllObjects failure [skip-bc] (gen…
Browse files Browse the repository at this point in the history
…erated)

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]>
  • Loading branch information
3 people committed Dec 31, 2024
1 parent 7e0027e commit 93eb697
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/Bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 49 additions & 43 deletions packages/client-search/src/searchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand Down

0 comments on commit 93eb697

Please sign in to comment.