up
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user