Skip to content

Commit 826cb2a

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 0a5b7ec commit 826cb2a

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
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

src/main/scala/algoliasearch/extension/package.scala

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -366,50 +366,58 @@ package object extension {
366366
)(implicit ec: ExecutionContext): Future[ReplaceAllObjectsResponse] = {
367367
val tmpIndexName = s"${indexName}_tmp_${scala.util.Random.nextInt(100)}"
368368

369-
for {
370-
copy <- client.operationIndex(
371-
indexName = indexName,
372-
operationIndexParams = OperationIndexParams(
373-
operation = OperationType.Copy,
374-
destination = tmpIndexName,
375-
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
376-
),
377-
requestOptions = requestOptions
378-
)
369+
try {
370+
for {
371+
copy <- client.operationIndex(
372+
indexName = indexName,
373+
operationIndexParams = OperationIndexParams(
374+
operation = OperationType.Copy,
375+
destination = tmpIndexName,
376+
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
377+
),
378+
requestOptions = requestOptions
379+
)
379380

380-
batchResponses <- chunkedBatch(
381-
indexName = tmpIndexName,
382-
objects = objects,
383-
action = Action.AddObject,
384-
waitForTasks = true,
385-
batchSize = batchSize,
386-
requestOptions = requestOptions
387-
)
381+
batchResponses <- chunkedBatch(
382+
indexName = tmpIndexName,
383+
objects = objects,
384+
action = Action.AddObject,
385+
waitForTasks = true,
386+
batchSize = batchSize,
387+
requestOptions = requestOptions
388+
)
388389

389-
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
390+
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
390391

391-
copy <- client.operationIndex(
392-
indexName = indexName,
393-
operationIndexParams = OperationIndexParams(
394-
operation = OperationType.Copy,
395-
destination = tmpIndexName,
396-
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
397-
),
398-
requestOptions = requestOptions
399-
)
400-
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
392+
copy <- client.operationIndex(
393+
indexName = indexName,
394+
operationIndexParams = OperationIndexParams(
395+
operation = OperationType.Copy,
396+
destination = tmpIndexName,
397+
scope = Some(Seq(ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms))
398+
),
399+
requestOptions = requestOptions
400+
)
401+
_ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
401402

402-
move <- client.operationIndex(
403-
indexName = tmpIndexName,
404-
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
405-
requestOptions = requestOptions
403+
move <- client.operationIndex(
404+
indexName = tmpIndexName,
405+
operationIndexParams = OperationIndexParams(operation = OperationType.Move, destination = indexName),
406+
requestOptions = requestOptions
407+
)
408+
_ <- client.waitTask(indexName = tmpIndexName, taskID = move.taskID, requestOptions = requestOptions)
409+
} yield ReplaceAllObjectsResponse(
410+
copyOperationResponse = copy,
411+
batchResponses = batchResponses,
412+
moveOperationResponse = move
406413
)
407-
_ <- client.waitTask(indexName = tmpIndexName, taskID = move.taskID, requestOptions = requestOptions)
408-
} yield ReplaceAllObjectsResponse(
409-
copyOperationResponse = copy,
410-
batchResponses = batchResponses,
411-
moveOperationResponse = move
412-
)
414+
} catch {
415+
case e: Throwable => {
416+
client.deleteIndex(tmpIndexName)
417+
418+
throw e
419+
}
420+
}
413421
}
414422

415423
/** Check if an index exists.

0 commit comments

Comments
 (0)