Add operational health, encrypted backups and isolated restore drills
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user