Skip to content

Commit 858216c

Browse files
committed
implement create snapshot
1 parent 5bde104 commit 858216c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,3 +795,5 @@ update_dictionary_1: |-
795795
await client.Index("books").UpdateDictionaryAsync(newDictionary);
796796
reset_dictionary_1: |-
797797
await client.Index("books").ResetDictionaryAsync();
798+
create_snapshot_1: |-
799+
await client.CreateSnapshotAsync();

src/Meilisearch/MeilisearchClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ public async Task<TaskInfo> CreateDumpAsync(CancellationToken cancellationToken
284284
return await response.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
285285
}
286286

287+
/// <summary>
288+
/// Creates Snapshot process.
289+
/// </summary>
290+
/// <param name="cancellationToken">The cancellation token for this call.</param>
291+
/// <returns>Returns snapshot creation status with uid and processing status.</returns>
292+
public async Task<TaskInfo> CreateSnapshotAsync(CancellationToken cancellationToken = default)
293+
{
294+
var response = await _http.PostAsync("snapshots", default, cancellationToken).ConfigureAwait(false);
295+
return await response.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
296+
}
297+
287298
/// <summary>
288299
/// Gets the API keys.
289300
/// </summary>

tests/Meilisearch.Tests/MeilisearchClientTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ public async Task CreateAndGetDumps()
9292
Assert.Equal(dumpResponse.TaskUid, dumpTask.Uid);
9393
}
9494

95+
[Fact]
96+
public async Task CreateAndGetSnapshots()
97+
{
98+
var snapshotResponse = await _defaultClient.CreateSnapshotAsync();
99+
Assert.NotNull(snapshotResponse);
100+
101+
snapshotResponse.Status.Should().Be(TaskInfoStatus.Enqueued);
102+
103+
var snapshotTask = await _defaultClient.GetTaskAsync(snapshotResponse.TaskUid);
104+
snapshotTask.Status.Should().BeOneOf(TaskInfoStatus.Succeeded, TaskInfoStatus.Processing, TaskInfoStatus.Enqueued);
105+
Assert.Equal(snapshotResponse.TaskUid, snapshotTask.Uid);
106+
}
107+
95108
[Fact]
96109
public async Task CancelTasks()
97110
{

0 commit comments

Comments
 (0)