Track manual snapshots and apply versioned camera config
This commit is contained in:
1 parent
f4a8f4a668
commit
8f00f69a5f
30 files changed
+645
-63
No files matched your search
@@ -143,6 +143,32 @@ public sealed class AlarikStorageProvider : IStorageProvider, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> CleanupStagingAsync(DateTime olderThanUtc, CancellationToken ct = default)
|
||||
{
|
||||
if (_client is null)
|
||||
throw new InvalidOperationException("Alarik/S3 storage is not configured");
|
||||
|
||||
var deleted = 0;
|
||||
string? continuationToken = null;
|
||||
do
|
||||
{
|
||||
var page = await _client.ListObjectsV2Async(new ListObjectsV2Request
|
||||
{
|
||||
BucketName = _bucket,
|
||||
Prefix = "staging/",
|
||||
ContinuationToken = continuationToken,
|
||||
}, ct).ConfigureAwait(false);
|
||||
var expired = page.S3Objects
|
||||
.Where(obj => obj.LastModified is DateTime modified && modified.ToUniversalTime() < olderThanUtc)
|
||||
.Select(obj => obj.Key)
|
||||
.ToArray();
|
||||
await DeleteBatchAsync(expired, ct).ConfigureAwait(false);
|
||||
deleted += expired.Length;
|
||||
continuationToken = page.IsTruncated == true ? page.NextContinuationToken : null;
|
||||
} while (continuationToken is not null);
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public async Task<bool> HealthCheckAsync(CancellationToken ct = default)
|
||||
{
|
||||
if (_client is null)
|
||||
|
||||
@@ -107,6 +107,48 @@ public sealed class LocalStorageProvider : IStorageProvider
|
||||
}
|
||||
}
|
||||
|
||||
public Task<int> CleanupStagingAsync(DateTime olderThanUtc, CancellationToken ct = default)
|
||||
{
|
||||
if (!Directory.Exists(_root))
|
||||
return Task.FromResult(0);
|
||||
|
||||
EnsureNoLinks(_root);
|
||||
var deleted = 0;
|
||||
var pending = new Stack<string>();
|
||||
pending.Push(_root);
|
||||
while (pending.Count > 0)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
var directory = pending.Pop();
|
||||
EnsureNoLinks(directory);
|
||||
foreach (var entry in Directory.EnumerateFileSystemEntries(directory))
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
// Never follow a link, including a dangling link.
|
||||
if (new FileInfo(entry).LinkTarget is not null ||
|
||||
(File.GetAttributes(entry) & FileAttributes.ReparsePoint) != 0)
|
||||
continue;
|
||||
if (Directory.Exists(entry))
|
||||
{
|
||||
pending.Push(entry);
|
||||
continue;
|
||||
}
|
||||
var name = Path.GetFileName(entry);
|
||||
var marker = name.LastIndexOf(".tmp-", StringComparison.Ordinal);
|
||||
if (marker < 1 || name.Length != marker + 5 + 32 ||
|
||||
!Guid.TryParseExact(name[(marker + 5)..], "N", out _))
|
||||
continue;
|
||||
var info = new FileInfo(entry);
|
||||
if (info.LastWriteTimeUtc >= olderThanUtc)
|
||||
continue;
|
||||
EnsureNoLinks(entry);
|
||||
File.Delete(entry);
|
||||
deleted++;
|
||||
}
|
||||
}
|
||||
return Task.FromResult(deleted);
|
||||
}
|
||||
|
||||
public Task<bool> HealthCheckAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -209,6 +209,13 @@ public sealed class StorageProviderFactory : IStorageProvider, Heimdall.Applicat
|
||||
finally { DisposeProvider(provider); }
|
||||
}
|
||||
|
||||
public async Task<int> CleanupStagingAsync(DateTime olderThanUtc, CancellationToken ct = default)
|
||||
{
|
||||
var provider = Resolve();
|
||||
try { return await provider.CleanupStagingAsync(olderThanUtc, ct).ConfigureAwait(false); }
|
||||
finally { DisposeProvider(provider); }
|
||||
}
|
||||
|
||||
private static void DisposeProvider(IStorageProvider provider) => (provider as IDisposable)?.Dispose();
|
||||
|
||||
private IStorageProvider Resolve(string? providerOverride = null)
|
||||
|
||||
Reference in new issue
Block a user