Skip to content

Commit 8674860

Browse files
meili-bors[bot]danFbachcurquiza
authored
Merge #593
593: Add snapshot creation method r=curquiza a=danFbach # Pull Request ## Related issue Fixes #501 ## What does this PR do? -implements snapshots ## 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? Added a unit test even though issue didn't directly request. basically a clone on `CreateAndGetDumps()` test, but for snapshots task. Co-authored-by: Dan Fehrenbach <[email protected]> Co-authored-by: Clémentine <[email protected]>
2 parents 81fd8a3 + 00752f0 commit 8674860

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

.code-samples.meilisearch.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,8 @@ update_dictionary_1: |-
813813
await client.Index("books").UpdateDictionaryAsync(newDictionary);
814814
reset_dictionary_1: |-
815815
await client.Index("books").ResetDictionaryAsync();
816+
create_snapshot_1: |-
817+
await client.CreateSnapshotAsync();
816818
get_search_cutoff_1: |-
817819
var searchCutoff = await client.Index("movies").GetSearchCutoffMsAsync();
818820
update_search_cutoff_1: |-

src/Meilisearch/MeilisearchClient.cs

+11
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

+13
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)