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 ed3a3c0 commit 735c457
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 89 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
188 changes: 100 additions & 88 deletions algoliasearch/search/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,57 +620,63 @@ async def replace_all_objects(
"""
tmp_index_name = self.create_temporary_name(index_name)

async def _copy() -> UpdatedAtResponse:
return await self.operation_index(
index_name=index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.COPY,
destination=tmp_index_name,
scope=[
ScopeType("settings"),
ScopeType("rules"),
ScopeType("synonyms"),
],
),
try:

async def _copy() -> UpdatedAtResponse:
return await self.operation_index(
index_name=index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.COPY,
destination=tmp_index_name,
scope=[
ScopeType("settings"),
ScopeType("rules"),
ScopeType("synonyms"),
],
),
request_options=request_options,
)

copy_operation_response = await _copy()

batch_responses = await self.chunked_batch(
index_name=tmp_index_name,
objects=objects,
wait_for_tasks=True,
batch_size=batch_size,
request_options=request_options,
)

copy_operation_response = await _copy()

batch_responses = await self.chunked_batch(
index_name=tmp_index_name,
objects=objects,
wait_for_tasks=True,
batch_size=batch_size,
request_options=request_options,
)
await self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)

await self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)
copy_operation_response = await _copy()
await self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)

copy_operation_response = await _copy()
await self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)
move_operation_response = await self.operation_index(
index_name=tmp_index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.MOVE,
destination=index_name,
),
request_options=request_options,
)
await self.wait_for_task(
index_name=tmp_index_name, task_id=move_operation_response.task_id
)

move_operation_response = await self.operation_index(
index_name=tmp_index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.MOVE,
destination=index_name,
),
request_options=request_options,
)
await self.wait_for_task(
index_name=tmp_index_name, task_id=move_operation_response.task_id
)
return ReplaceAllObjectsResponse(
copy_operation_response=copy_operation_response,
batch_responses=batch_responses,
move_operation_response=move_operation_response,
)
except Exception as e:
await self.delete_index(tmp_index_name)

return ReplaceAllObjectsResponse(
copy_operation_response=copy_operation_response,
batch_responses=batch_responses,
move_operation_response=move_operation_response,
)
raise e

async def index_exists(self, index_name: str) -> bool:
"""
Expand Down Expand Up @@ -5658,57 +5664,63 @@ def replace_all_objects(
"""
tmp_index_name = self.create_temporary_name(index_name)

def _copy() -> UpdatedAtResponse:
return self.operation_index(
index_name=index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.COPY,
destination=tmp_index_name,
scope=[
ScopeType("settings"),
ScopeType("rules"),
ScopeType("synonyms"),
],
),
try:

def _copy() -> UpdatedAtResponse:
return self.operation_index(
index_name=index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.COPY,
destination=tmp_index_name,
scope=[
ScopeType("settings"),
ScopeType("rules"),
ScopeType("synonyms"),
],
),
request_options=request_options,
)

copy_operation_response = _copy()

batch_responses = self.chunked_batch(
index_name=tmp_index_name,
objects=objects,
wait_for_tasks=True,
batch_size=batch_size,
request_options=request_options,
)

copy_operation_response = _copy()

batch_responses = self.chunked_batch(
index_name=tmp_index_name,
objects=objects,
wait_for_tasks=True,
batch_size=batch_size,
request_options=request_options,
)
self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)

self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)
copy_operation_response = _copy()
self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)

copy_operation_response = _copy()
self.wait_for_task(
index_name=tmp_index_name, task_id=copy_operation_response.task_id
)
move_operation_response = self.operation_index(
index_name=tmp_index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.MOVE,
destination=index_name,
),
request_options=request_options,
)
self.wait_for_task(
index_name=tmp_index_name, task_id=move_operation_response.task_id
)

move_operation_response = self.operation_index(
index_name=tmp_index_name,
operation_index_params=OperationIndexParams(
operation=OperationType.MOVE,
destination=index_name,
),
request_options=request_options,
)
self.wait_for_task(
index_name=tmp_index_name, task_id=move_operation_response.task_id
)
return ReplaceAllObjectsResponse(
copy_operation_response=copy_operation_response,
batch_responses=batch_responses,
move_operation_response=move_operation_response,
)
except Exception as e:
self.delete_index(tmp_index_name)

return ReplaceAllObjectsResponse(
copy_operation_response=copy_operation_response,
batch_responses=batch_responses,
move_operation_response=move_operation_response,
)
raise e

def index_exists(self, index_name: str) -> bool:
"""
Expand Down

0 comments on commit 735c457

Please sign in to comment.