Files
git.stella-ops.org/src/Concelier/StellaOps.Concelier.WebService/DualWrite/DualWriteAdvisoryStore.cs

55 lines
1.9 KiB
C#

using Microsoft.Extensions.Logging;
using StellaOps.Concelier.Models;
using StellaOps.Concelier.Storage.Advisories;
using StellaOps.Concelier.Persistence.Postgres.Advisories;
namespace StellaOps.Concelier.WebService.DualWrite;
/// <summary>
/// Postgres-backed advisory store that implements the legacy storage contracts.
/// </summary>
public sealed class DualWriteAdvisoryStore : IAdvisoryStore
{
private readonly IPostgresAdvisoryStore _postgresStore;
private readonly ILogger<DualWriteAdvisoryStore> _logger;
public DualWriteAdvisoryStore(IPostgresAdvisoryStore postgresStore, ILogger<DualWriteAdvisoryStore> logger)
{
_postgresStore = postgresStore ?? throw new ArgumentNullException(nameof(postgresStore));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
/// <inheritdoc />
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;
}
}
/// <inheritdoc />
public Task<Advisory?> FindAsync(string advisoryKey, CancellationToken cancellationToken)
{
return _postgresStore.FindAsync(advisoryKey, cancellationToken);
}
/// <inheritdoc />
public Task<IReadOnlyList<Advisory>> GetRecentAsync(int limit, CancellationToken cancellationToken)
{
return _postgresStore.GetRecentAsync(limit, cancellationToken);
}
/// <inheritdoc />
public IAsyncEnumerable<Advisory> StreamAsync(CancellationToken cancellationToken)
{
return _postgresStore.StreamAsync(cancellationToken);
}
}