Add Notifiarr support (#52)

This commit is contained in:
Marius Nechifor
2025-02-02 20:45:50 +02:00
parent 1713d0fd1e
commit 19b3675701
46 changed files with 834 additions and 25 deletions
@@ -0,0 +1,45 @@
using Infrastructure.Verticals.Notifications.Models;
using MassTransit;
using Microsoft.Extensions.Logging;
namespace Infrastructure.Verticals.Notifications.Consumers;
public sealed class NotificationConsumer<T> : IConsumer<T> where T : Notification
{
private readonly ILogger<NotificationConsumer<T>> _logger;
private readonly NotificationService _notificationService;
public NotificationConsumer(ILogger<NotificationConsumer<T>> logger, NotificationService notificationService)
{
_logger = logger;
_notificationService = notificationService;
}
public async Task Consume(ConsumeContext<T> context)
{
try
{
switch (context.Message)
{
case FailedImportStrikeNotification failedMessage:
await _notificationService.Notify(failedMessage);
break;
case StalledStrikeNotification stalledMessage:
await _notificationService.Notify(stalledMessage);
break;
case QueueItemDeleteNotification queueItemDeleteMessage:
await _notificationService.Notify(queueItemDeleteMessage);
break;
default:
throw new NotImplementedException();
}
// prevent spamming
await Task.Delay(1000);
}
catch (Exception exception)
{
_logger.LogError(exception, "error while processing notifications");
}
}
}