Skip to content

Commit 6144f9b

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 5bc6978 commit 6144f9b

File tree

2 files changed

+57
-51
lines changed

2 files changed

+57
-51
lines changed

.github/ISSUE_TEMPLATE/Bug_report.yml

+1-1
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

lib/algolia/api/search_client.rb

+56-50
Original file line numberDiff line numberDiff line change
@@ -3478,63 +3478,69 @@ def chunked_batch(
34783478
def replace_all_objects(index_name, objects, batch_size = 1000, request_options = {})
34793479
tmp_index_name = index_name + "_tmp_" + rand(10_000_000).to_s
34803480

3481-
copy_operation_response = operation_index(
3482-
index_name,
3483-
Search::OperationIndexParams.new(
3484-
operation: Search::OperationType::COPY,
3485-
destination: tmp_index_name,
3486-
scope: [
3487-
Search::ScopeType::SETTINGS,
3488-
Search::ScopeType::RULES,
3489-
Search::ScopeType::SYNONYMS
3490-
]
3491-
),
3492-
request_options
3493-
)
3481+
begin
3482+
copy_operation_response = operation_index(
3483+
index_name,
3484+
Search::OperationIndexParams.new(
3485+
operation: Search::OperationType::COPY,
3486+
destination: tmp_index_name,
3487+
scope: [
3488+
Search::ScopeType::SETTINGS,
3489+
Search::ScopeType::RULES,
3490+
Search::ScopeType::SYNONYMS
3491+
]
3492+
),
3493+
request_options
3494+
)
34943495

3495-
batch_responses = chunked_batch(
3496-
tmp_index_name,
3497-
objects,
3498-
Search::Action::ADD_OBJECT,
3499-
true,
3500-
batch_size,
3501-
request_options
3502-
)
3496+
batch_responses = chunked_batch(
3497+
tmp_index_name,
3498+
objects,
3499+
Search::Action::ADD_OBJECT,
3500+
true,
3501+
batch_size,
3502+
request_options
3503+
)
35033504

3504-
wait_for_task(tmp_index_name, copy_operation_response.task_id)
3505+
wait_for_task(tmp_index_name, copy_operation_response.task_id)
3506+
3507+
copy_operation_response = operation_index(
3508+
index_name,
3509+
Search::OperationIndexParams.new(
3510+
operation: Search::OperationType::COPY,
3511+
destination: tmp_index_name,
3512+
scope: [
3513+
Search::ScopeType::SETTINGS,
3514+
Search::ScopeType::RULES,
3515+
Search::ScopeType::SYNONYMS
3516+
]
3517+
),
3518+
request_options
3519+
)
35053520

3506-
copy_operation_response = operation_index(
3507-
index_name,
3508-
Search::OperationIndexParams.new(
3509-
operation: Search::OperationType::COPY,
3510-
destination: tmp_index_name,
3511-
scope: [
3512-
Search::ScopeType::SETTINGS,
3513-
Search::ScopeType::RULES,
3514-
Search::ScopeType::SYNONYMS
3515-
]
3516-
),
3517-
request_options
3518-
)
3521+
wait_for_task(tmp_index_name, copy_operation_response.task_id)
35193522

3520-
wait_for_task(tmp_index_name, copy_operation_response.task_id)
3523+
move_operation_response = operation_index(
3524+
tmp_index_name,
3525+
Search::OperationIndexParams.new(
3526+
operation: Search::OperationType::MOVE,
3527+
destination: index_name
3528+
),
3529+
request_options
3530+
)
35213531

3522-
move_operation_response = operation_index(
3523-
tmp_index_name,
3524-
Search::OperationIndexParams.new(
3525-
operation: Search::OperationType::MOVE,
3526-
destination: index_name
3527-
),
3528-
request_options
3529-
)
3532+
wait_for_task(tmp_index_name, move_operation_response.task_id)
35303533

3531-
wait_for_task(tmp_index_name, move_operation_response.task_id)
3534+
Search::ReplaceAllObjectsResponse.new(
3535+
copy_operation_response: copy_operation_response,
3536+
batch_responses: batch_responses,
3537+
move_operation_response: move_operation_response
3538+
)
3539+
rescue Exception => e
3540+
delete_index(tmp_index_name)
35323541

3533-
Search::ReplaceAllObjectsResponse.new(
3534-
copy_operation_response: copy_operation_response,
3535-
batch_responses: batch_responses,
3536-
move_operation_response: move_operation_response
3537-
)
3542+
raise e
3543+
end
35383544
end
35393545

35403546
def index_exists?(index_name)

0 commit comments

Comments
 (0)