-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathDocsSync.cs
More file actions
104 lines (78 loc) · 3.55 KB
/
Copy pathDocsSync.cs
File metadata and controls
104 lines (78 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Elastic.Documentation.Deploying.Synchronization;
public interface IDocsSyncPlanStrategy
{
Task<SyncPlan> Plan(float? deleteThreshold, string[] excludePatterns, Cancel ctx = default);
}
public record PlanValidationResult(bool Valid, float DeleteRatio, float DeleteThreshold);
public interface IDocsSyncApplyStrategy
{
/// <returns>false if any file failed to upload or delete.</returns>
Task<bool> Apply(SyncPlan plan, Cancel ctx = default);
}
public record SyncRequest;
public record DeleteRequest : SyncRequest
{
[JsonPropertyName("destination_path")]
public required string DestinationPath { get; init; }
}
public record UploadRequest : SyncRequest
{
[JsonPropertyName("local_path")]
public required string LocalPath { get; init; }
[JsonPropertyName("destination_path")]
public required string DestinationPath { get; init; }
}
public record AddRequest : UploadRequest;
public record UpdateRequest : UploadRequest;
public record SkipRequest : SyncRequest
{
[JsonPropertyName("local_path")]
public required string LocalPath { get; init; }
[JsonPropertyName("destination_path")]
public required string DestinationPath { get; init; }
}
public record SyncPlan
{
/// The user-specified delete threshold
[JsonPropertyName("deletion_threshold_default")]
public required float? DeleteThresholdDefault { get; init; }
/// Glob patterns excluded from both local upload and remote deletion
[JsonPropertyName("exclude_patterns")]
public required string[] ExcludePatterns { get; init; }
/// The user-specified delete threshold
[JsonPropertyName("remote_listing_completed")]
public required bool RemoteListingCompleted { get; init; }
/// The total number of source files that were located in the build output
[JsonPropertyName("total_source_files")]
public required int TotalSourceFiles { get; init; }
/// The total number of remote files that were located in the remote location
[JsonPropertyName("total_remote_files")]
public required int TotalRemoteFiles { get; init; }
/// The total number of sync requests that were generated (sum of <see cref="AddRequests"/>, <see cref="UpdateRequests"/>, <see cref="DeleteRequests"/>)
[JsonPropertyName("total_sync_requests")]
public required int TotalSyncRequests { get; init; }
[JsonPropertyName("delete")]
public required IReadOnlyList<DeleteRequest> DeleteRequests { get; init; }
[JsonPropertyName("add")]
public required IReadOnlyList<AddRequest> AddRequests { get; init; }
[JsonPropertyName("update")]
public required IReadOnlyList<UpdateRequest> UpdateRequests { get; init; }
[JsonPropertyName("skip")]
public required IReadOnlyList<SkipRequest> SkipRequests { get; init; }
public static string Serialize(SyncPlan plan) => JsonSerializer.Serialize(plan, SyncSerializerContext.Default.SyncPlan);
public static SyncPlan Deserialize(string json) =>
JsonSerializer.Deserialize(json, SyncSerializerContext.Default.SyncPlan) ??
throw new JsonException("Failed to deserialize SyncPlan from JSON");
}
[JsonSourceGenerationOptions(WriteIndented = true, UseStringEnumConverter = true)]
[JsonSerializable(typeof(SyncPlan))]
[JsonSerializable(typeof(AddRequest))]
[JsonSerializable(typeof(UpdateRequest))]
[JsonSerializable(typeof(DeleteRequest))]
[JsonSerializable(typeof(SkipRequest))]
public sealed partial class SyncSerializerContext : JsonSerializerContext;