43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using StellaOps.Policy.Engine.ExceptionCache;
|
|
|
|
namespace StellaOps.Policy.Engine.Events;
|
|
|
|
/// <summary>
|
|
/// Publishes exception lifecycle events and keeps local caches warm.
|
|
/// </summary>
|
|
public interface IExceptionEventPublisher
|
|
{
|
|
Task PublishAsync(ExceptionEvent exceptionEvent, CancellationToken cancellationToken = default);
|
|
}
|
|
|
|
internal sealed class LoggingExceptionEventPublisher : IExceptionEventPublisher
|
|
{
|
|
private readonly IExceptionEffectiveCache? _cache;
|
|
private readonly ILogger<LoggingExceptionEventPublisher> _logger;
|
|
|
|
public LoggingExceptionEventPublisher(
|
|
IExceptionEffectiveCache? cache,
|
|
ILogger<LoggingExceptionEventPublisher> logger)
|
|
{
|
|
_cache = cache;
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
}
|
|
|
|
public async Task PublishAsync(ExceptionEvent exceptionEvent, CancellationToken cancellationToken = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(exceptionEvent);
|
|
|
|
if (_cache is not null)
|
|
{
|
|
await _cache.HandleExceptionEventAsync(exceptionEvent, cancellationToken).ConfigureAwait(false);
|
|
}
|
|
|
|
_logger.LogInformation(
|
|
"Published exception event {EventType} for exception {ExceptionId} tenant {TenantId}",
|
|
exceptionEvent.EventType,
|
|
exceptionEvent.ExceptionId,
|
|
exceptionEvent.TenantId);
|
|
}
|
|
}
|