Skip to content

Commit 083d6b9

Browse files
meili-bors[bot]Pavel Belokonpbelokonsanders41
authored
Merge #885
885: implemented createSnapshot method and created entry with create_snaps… r=sanders41 a=pbelokon # Pull Request ## Related issue Fixes #884 ## What does this PR do? This pr Implements the new createSnapshot method in the meilisearch\client.py, also creates a new entry with the key "create_snapshot_1:" in the .code-samples.meilisearch.yml ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Pavel Belokon <[email protected]> Co-authored-by: Pavel Belokon <[email protected]> Co-authored-by: Paul Sanders <[email protected]>
2 parents fdd848a + 5dd994d commit 083d6b9

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.code-samples.meilisearch.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ getting_started_typo_tolerance: |-
216216
'oneTypo': 4
217217
}
218218
})
219-
get_typo_tolerance_1:
219+
get_typo_tolerance_1: |-
220220
client.index('books').get_typo_tolerance()
221221
update_typo_tolerance_1: |-
222222
client.index('books').update_typo_tolerance({
@@ -701,3 +701,5 @@ update_dictionary_1: |-
701701
client.index('books').update_dictionary(["J. R. R.", "W. E. B."])
702702
reset_dictionary_1: |-
703703
client.index('books').reset_dictionary()
704+
create_snapshot_1: |-
705+
client.create_snapshot()

meilisearch/client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,24 @@ def create_dump(self) -> TaskInfo:
457457

458458
return TaskInfo(**task)
459459

460+
def create_snapshot(self) -> TaskInfo:
461+
"""Trigger the creation of a Meilisearch snapshot.
462+
463+
Returns
464+
-------
465+
task_info:
466+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
467+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
468+
469+
Raises
470+
------
471+
MeilisearchApiError
472+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
473+
"""
474+
task = self.http.post(self.config.paths.snapshots)
475+
476+
return TaskInfo(**task)
477+
460478
def swap_indexes(self, parameters: List[Mapping[str, List[str]]]) -> TaskInfo:
461479
"""Swap two indexes.
462480

meilisearch/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Paths:
3131
sortable_attributes = "sortable-attributes"
3232
typo_tolerance = "typo-tolerance"
3333
dumps = "dumps"
34+
snapshots = "snapshots"
3435
pagination = "pagination"
3536
faceting = "faceting"
3637
dictionary = "dictionary"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# pylint: disable=invalid-name
2+
3+
4+
def test_snapshot_creation(client, index_with_documents):
5+
"""Tests the creation of a Meilisearch snapshot."""
6+
index_with_documents("indexUID-snapshot-creation")
7+
snapshot = client.create_snapshot()
8+
client.wait_for_task(snapshot.task_uid)
9+
snapshot_status = client.get_task(snapshot.task_uid)
10+
assert snapshot_status.status == "succeeded"
11+
assert snapshot_status.type == "snapshotCreation"

0 commit comments

Comments
 (0)