Add Notifiarr support (#52)
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user