Skip to content

Commit

Permalink
Update for meilisearch-python-sdk 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sanders41 committed Oct 4, 2023
1 parent a63743c commit 6e54fac
Show file tree
Hide file tree
Showing 4 changed files with 600 additions and 590 deletions.
4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from meilisearch_python_async import Client
from meilisearch_python_sdk import AsyncClient

client = Client(
client = AsyncClient(
"http://localhost:7700",
)
19 changes: 9 additions & 10 deletions meilisync/meili.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from typing import AsyncGenerator, List, Optional, Type, Union

from loguru import logger
from meilisearch_python_async import Client
from meilisearch_python_async.errors import MeilisearchApiError
from meilisearch_python_async.task import wait_for_task
from meilisearch_python_sdk import AsyncClient
from meilisearch_python_sdk.errors import MeilisearchApiError

from meilisync.enums import EventType
from meilisync.event import EventCollection
Expand All @@ -21,7 +20,7 @@ def __init__(
plugins: Optional[List[Union[Type[Plugin], Plugin]]] = None,
wait_for_task_timeout: Optional[int] = None,
):
self.client = Client(
self.client = AsyncClient(
api_url,
api_key,
)
Expand All @@ -48,22 +47,22 @@ async def refresh_data(self, index: str, pk: str, data: AsyncGenerator):
index_tmp = await self.client.create_index(index_name_tmp, primary_key=pk)
task = await index_tmp.update_settings(settings)
logger.info(f"Waiting for update tmp index {index_name_tmp} settings to complete...")
await wait_for_task(
client=self.client, task_id=task.task_uid, timeout_in_ms=self.wait_for_task_timeout
await self.client.wait_for_task(
task_id=task.task_uid, timeout_in_ms=self.wait_for_task_timeout
)
tasks, count = await self.add_full_data(index_name_tmp, pk, data)
wait_tasks = [
wait_for_task(
client=self.client, task_id=item.task_uid, timeout_in_ms=self.wait_for_task_timeout
self.client.wait_for_task(
task_id=item.task_uid, timeout_in_ms=self.wait_for_task_timeout
)
for item in tasks
]
logger.info(f"Waiting for insert tmp index {index_name_tmp} to complete...")
await asyncio.gather(*wait_tasks)
task = await self.client.swap_indexes([(index, index_name_tmp)])
logger.info(f"Waiting for swap index {index} to complete...")
await wait_for_task(
client=self.client, task_id=task.task_uid, timeout_in_ms=self.wait_for_task_timeout
await self.client.wait_for_task(
task_id=task.task_uid, timeout_in_ms=self.wait_for_task_timeout
)
await self.client.index(index_name_tmp).delete()
logger.success(f"Swap index {index} complete")
Expand Down
Loading

0 comments on commit 6e54fac

Please sign in to comment.