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 5bc6978 commit 6144f9b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 51 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
106 changes: 56 additions & 50 deletions lib/algolia/api/search_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3478,63 +3478,69 @@ def chunked_batch(
def replace_all_objects(index_name, objects, batch_size = 1000, request_options = {})
tmp_index_name = index_name + "_tmp_" + rand(10_000_000).to_s

copy_operation_response = operation_index(
index_name,
Search::OperationIndexParams.new(
operation: Search::OperationType::COPY,
destination: tmp_index_name,
scope: [
Search::ScopeType::SETTINGS,
Search::ScopeType::RULES,
Search::ScopeType::SYNONYMS
]
),
request_options
)
begin
copy_operation_response = operation_index(
index_name,
Search::OperationIndexParams.new(
operation: Search::OperationType::COPY,
destination: tmp_index_name,
scope: [
Search::ScopeType::SETTINGS,
Search::ScopeType::RULES,
Search::ScopeType::SYNONYMS
]
),
request_options
)

batch_responses = chunked_batch(
tmp_index_name,
objects,
Search::Action::ADD_OBJECT,
true,
batch_size,
request_options
)
batch_responses = chunked_batch(
tmp_index_name,
objects,
Search::Action::ADD_OBJECT,
true,
batch_size,
request_options
)

wait_for_task(tmp_index_name, copy_operation_response.task_id)
wait_for_task(tmp_index_name, copy_operation_response.task_id)

copy_operation_response = operation_index(
index_name,
Search::OperationIndexParams.new(
operation: Search::OperationType::COPY,
destination: tmp_index_name,
scope: [
Search::ScopeType::SETTINGS,
Search::ScopeType::RULES,
Search::ScopeType::SYNONYMS
]
),
request_options
)

copy_operation_response = operation_index(
index_name,
Search::OperationIndexParams.new(
operation: Search::OperationType::COPY,
destination: tmp_index_name,
scope: [
Search::ScopeType::SETTINGS,
Search::ScopeType::RULES,
Search::ScopeType::SYNONYMS
]
),
request_options
)
wait_for_task(tmp_index_name, copy_operation_response.task_id)

wait_for_task(tmp_index_name, copy_operation_response.task_id)
move_operation_response = operation_index(
tmp_index_name,
Search::OperationIndexParams.new(
operation: Search::OperationType::MOVE,
destination: index_name
),
request_options
)

move_operation_response = operation_index(
tmp_index_name,
Search::OperationIndexParams.new(
operation: Search::OperationType::MOVE,
destination: index_name
),
request_options
)
wait_for_task(tmp_index_name, move_operation_response.task_id)

wait_for_task(tmp_index_name, move_operation_response.task_id)
Search::ReplaceAllObjectsResponse.new(
copy_operation_response: copy_operation_response,
batch_responses: batch_responses,
move_operation_response: move_operation_response
)
rescue Exception => e
delete_index(tmp_index_name)

Search::ReplaceAllObjectsResponse.new(
copy_operation_response: copy_operation_response,
batch_responses: batch_responses,
move_operation_response: move_operation_response
)
raise e
end
end

def index_exists?(index_name)
Expand Down

0 comments on commit 6144f9b

Please sign in to comment.