Add operational health, encrypted backups and isolated restore drills

This commit is contained in:
wolf-demon
2026-09-21 09:10:54 +01:00
parent bc7cbc1492
commit 39751c5f1a
18 changed files with 542 additions and 7 deletions
+9
View File
@@ -7,6 +7,9 @@ namespace GuestOps.Web;
public interface IStore
{
Task Initialize();
Task Ping();
Task<DateTime?> WorkerLastSeen();
Task RecordWorkerHeartbeat();
Task<List<T>> List<T>(string hotel) where T : TenantDocument;
Task<T?> Get<T>(string hotel, string id) where T : TenantDocument;
Task Insert<T>(T document) where T : TenantDocument;
@@ -32,6 +35,9 @@ public interface IStore
}
public sealed class MongoStore : IStore
{
public async Task Ping()=>await db.RunCommandAsync<MongoDB.Bson.BsonDocument>(new MongoDB.Bson.BsonDocument("ping",1));
public async Task<DateTime?> WorkerLastSeen()=>(await db.GetCollection<WorkerHeartbeat>("workerheartbeat").Find(x=>x.Id=="worker").FirstOrDefaultAsync())?.At;
public async Task RecordWorkerHeartbeat()=>await db.GetCollection<WorkerHeartbeat>("workerheartbeat").ReplaceOneAsync(x=>x.Id=="worker",new WorkerHeartbeat(),new ReplaceOptions{IsUpsert=true});
public Task<List<Conversation>> Deliveries() => Collection<Conversation>().Find(x => x.Delivery != null && (x.Delivery.State == "Pending" || x.Delivery.State == "Sending")).SortBy(x => x.Delivery!.UpdatedAt).Limit(100).ToListAsync();
private readonly IMongoDatabase db;
public MongoStore(IConfiguration config)
@@ -141,6 +147,9 @@ public sealed class MongoStore : IStore
// Explicit Development-only preview store. Production never falls back to this.
public sealed class PreviewStore : IStore
{
public Task Ping()=>Task.CompletedTask;
public Task<DateTime?> WorkerLastSeen()=>Task.FromResult<DateTime?>(null);
public Task RecordWorkerHeartbeat()=>Task.CompletedTask;
public async Task<List<Conversation>> AutoReplyCandidates(string hotel,string mailbox,DateTime since)=>(await List<Conversation>(hotel)).Where(x=>x.MailboxId==mailbox&&x.AutoReplyCheckedAt==null&&x.ReceivedAt>=since).OrderBy(x=>x.ReceivedAt).Take(100).ToList();
public Task<bool> TryAutoReplyClaim(AutoReplyClaim claim)
{