Skip to content

Commit

Permalink
Merge #593
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people authored Jan 8, 2025
2 parents 81fd8a3 + 00752f0 commit 8674860
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ update_dictionary_1: |-
await client.Index("books").UpdateDictionaryAsync(newDictionary);
reset_dictionary_1: |-
await client.Index("books").ResetDictionaryAsync();
create_snapshot_1: |-
await client.CreateSnapshotAsync();
get_search_cutoff_1: |-
var searchCutoff = await client.Index("movies").GetSearchCutoffMsAsync();
update_search_cutoff_1: |-
Expand Down
11 changes: 11 additions & 0 deletions src/Meilisearch/MeilisearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ public async Task<TaskInfo> CreateDumpAsync(CancellationToken cancellationToken
return await response.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Creates Snapshot process.
/// </summary>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns snapshot creation status with uid and processing status.</returns>
public async Task<TaskInfo> CreateSnapshotAsync(CancellationToken cancellationToken = default)
{
var response = await _http.PostAsync("snapshots", default, cancellationToken).ConfigureAwait(false);
return await response.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Gets the API keys.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions tests/Meilisearch.Tests/MeilisearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ public async Task CreateAndGetDumps()
Assert.Equal(dumpResponse.TaskUid, dumpTask.Uid);
}

[Fact]
public async Task CreateAndGetSnapshots()
{
var snapshotResponse = await _defaultClient.CreateSnapshotAsync();
Assert.NotNull(snapshotResponse);

snapshotResponse.Status.Should().Be(TaskInfoStatus.Enqueued);

var snapshotTask = await _defaultClient.GetTaskAsync(snapshotResponse.TaskUid);
snapshotTask.Status.Should().BeOneOf(TaskInfoStatus.Succeeded, TaskInfoStatus.Processing, TaskInfoStatus.Enqueued);
Assert.Equal(snapshotResponse.TaskUid, snapshotTask.Uid);
}

[Fact]
public async Task CancelTasks()
{
Expand Down

0 comments on commit 8674860

Please sign in to comment.