using Microsoft.Extensions.Logging; using StellaOps.Concelier.Models; using StellaOps.Concelier.Storage.Advisories; using StellaOps.Concelier.Persistence.Postgres.Advisories; namespace StellaOps.Concelier.WebService.DualWrite; /// /// Postgres-backed advisory store that implements the legacy storage contracts. /// public sealed class DualWriteAdvisoryStore : IAdvisoryStore { private readonly IPostgresAdvisoryStore _postgresStore; private readonly ILogger _logger; public DualWriteAdvisoryStore(IPostgresAdvisoryStore postgresStore, ILogger logger) { _postgresStore = postgresStore ?? throw new ArgumentNullException(nameof(postgresStore)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } /// public async Task UpsertAsync(Advisory advisory, CancellationToken cancellationToken) { try { await _postgresStore.UpsertAsync(advisory, sourceId: null, cancellationToken).ConfigureAwait(false); _logger.LogDebug("Stored advisory {AdvisoryKey} in PostgreSQL", advisory.AdvisoryKey); } catch (Exception ex) { _logger.LogWarning(ex, "PostgreSQL advisory write failed for {AdvisoryKey}", advisory.AdvisoryKey); throw; } } /// public Task FindAsync(string advisoryKey, CancellationToken cancellationToken) { return _postgresStore.FindAsync(advisoryKey, cancellationToken); } /// public Task> GetRecentAsync(int limit, CancellationToken cancellationToken) { return _postgresStore.GetRecentAsync(limit, cancellationToken); } /// public IAsyncEnumerable StreamAsync(CancellationToken cancellationToken) { return _postgresStore.StreamAsync(cancellationToken); } }