From bd28c7ab05ff996b716962e7a5baa03f54380f8d Mon Sep 17 00:00:00 2001 From: Flaminel Date: Tue, 8 Apr 2025 22:20:51 +0300 Subject: [PATCH] Fix missing notifications for new strike types (#112) --- README.md | 1 + .../Notification/NotificationConfig.cs | 5 ++++- code/Executable/DependencyInjection/MainDI.cs | 2 ++ code/Executable/appsettings.Development.json | 1 + code/Executable/appsettings.json | 1 + .../Consumers/NotificationConsumer.cs | 3 +++ .../Notifications/INotificationFactory.cs | 2 ++ .../Notifications/INotificationProvider.cs | 2 ++ .../Models/SlowStrikeNotification.cs | 5 +++++ .../Notifications/Notifiarr/NotifiarrProvider.cs | 5 +++++ .../Notifications/NotificationFactory.cs | 5 +++++ .../Notifications/NotificationProvider.cs | 2 ++ .../Notifications/NotificationPublisher.cs | 5 +++++ .../Notifications/NotificationService.cs | 15 +++++++++++++++ code/test/docker-compose.yml | 13 +++++++------ variables.md | 9 ++++++++- 16 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 code/Infrastructure/Verticals/Notifications/Models/SlowStrikeNotification.cs diff --git a/README.md b/README.md index 6042d304..4aa1708d 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,7 @@ services: - NOTIFIARR__ON_IMPORT_FAILED_STRIKE=true - NOTIFIARR__ON_STALLED_STRIKE=true + - NOTIFIARR__ON_SLOW_STRIKE=true - NOTIFIARR__ON_QUEUE_ITEM_DELETED=true - NOTIFIARR__ON_DOWNLOAD_CLEANED=true - NOTIFIARR__API_KEY=notifiarr_secret diff --git a/code/Common/Configuration/Notification/NotificationConfig.cs b/code/Common/Configuration/Notification/NotificationConfig.cs index 18e74156..369b084b 100644 --- a/code/Common/Configuration/Notification/NotificationConfig.cs +++ b/code/Common/Configuration/Notification/NotificationConfig.cs @@ -10,13 +10,16 @@ public abstract record NotificationConfig [ConfigurationKeyName("ON_STALLED_STRIKE")] public bool OnStalledStrike { get; init; } + [ConfigurationKeyName("ON_SLOW_STRIKE")] + public bool OnSlowStrike { get; init; } + [ConfigurationKeyName("ON_QUEUE_ITEM_DELETED")] public bool OnQueueItemDeleted { get; init; } [ConfigurationKeyName("ON_DOWNLOAD_CLEANED")] public bool OnDownloadCleaned { get; init; } - public bool IsEnabled => OnImportFailedStrike || OnStalledStrike || OnQueueItemDeleted || OnDownloadCleaned; + public bool IsEnabled => OnImportFailedStrike || OnStalledStrike || OnSlowStrike || OnQueueItemDeleted || OnDownloadCleaned; public abstract bool IsValid(); } \ No newline at end of file diff --git a/code/Executable/DependencyInjection/MainDI.cs b/code/Executable/DependencyInjection/MainDI.cs index 1631be33..4cbf7354 100644 --- a/code/Executable/DependencyInjection/MainDI.cs +++ b/code/Executable/DependencyInjection/MainDI.cs @@ -25,6 +25,7 @@ public static class MainDI { config.AddConsumer>(); config.AddConsumer>(); + config.AddConsumer>(); config.AddConsumer>(); config.AddConsumer>(); @@ -34,6 +35,7 @@ public static class MainDI { e.ConfigureConsumer>(context); e.ConfigureConsumer>(context); + e.ConfigureConsumer>(context); e.ConfigureConsumer>(context); e.ConfigureConsumer>(context); e.ConcurrentMessageLimit = 1; diff --git a/code/Executable/appsettings.Development.json b/code/Executable/appsettings.Development.json index 81fc79ef..e70be6e7 100644 --- a/code/Executable/appsettings.Development.json +++ b/code/Executable/appsettings.Development.json @@ -117,6 +117,7 @@ "Notifiarr": { "ON_IMPORT_FAILED_STRIKE": true, "ON_STALLED_STRIKE": true, + "ON_SLOW_STRIKE": true, "ON_QUEUE_ITEM_DELETED": true, "ON_DOWNLOAD_CLEANED": true, "API_KEY": "", diff --git a/code/Executable/appsettings.json b/code/Executable/appsettings.json index 5fa1fc78..1dc52479 100644 --- a/code/Executable/appsettings.json +++ b/code/Executable/appsettings.json @@ -100,6 +100,7 @@ "Notifiarr": { "ON_IMPORT_FAILED_STRIKE": false, "ON_STALLED_STRIKE": false, + "ON_SLOW_STRIKE": false, "ON_QUEUE_ITEM_DELETED": false, "ON_DOWNLOAD_CLEANED": false, "API_KEY": "", diff --git a/code/Infrastructure/Verticals/Notifications/Consumers/NotificationConsumer.cs b/code/Infrastructure/Verticals/Notifications/Consumers/NotificationConsumer.cs index 297ce561..f3c6f148 100644 --- a/code/Infrastructure/Verticals/Notifications/Consumers/NotificationConsumer.cs +++ b/code/Infrastructure/Verticals/Notifications/Consumers/NotificationConsumer.cs @@ -27,6 +27,9 @@ public sealed class NotificationConsumer : IConsumer where T : Notificatio case StalledStrikeNotification stalledMessage: await _notificationService.Notify(stalledMessage); break; + case SlowStrikeNotification slowMessage: + await _notificationService.Notify(slowMessage); + break; case QueueItemDeletedNotification queueItemDeleteMessage: await _notificationService.Notify(queueItemDeleteMessage); break; diff --git a/code/Infrastructure/Verticals/Notifications/INotificationFactory.cs b/code/Infrastructure/Verticals/Notifications/INotificationFactory.cs index 5cf3d2eb..e68a9617 100644 --- a/code/Infrastructure/Verticals/Notifications/INotificationFactory.cs +++ b/code/Infrastructure/Verticals/Notifications/INotificationFactory.cs @@ -6,6 +6,8 @@ public interface INotificationFactory List OnStalledStrikeEnabled(); + List OnSlowStrikeEnabled(); + List OnQueueItemDeletedEnabled(); List OnDownloadCleanedEnabled(); diff --git a/code/Infrastructure/Verticals/Notifications/INotificationProvider.cs b/code/Infrastructure/Verticals/Notifications/INotificationProvider.cs index ea692538..c2cf2d8e 100644 --- a/code/Infrastructure/Verticals/Notifications/INotificationProvider.cs +++ b/code/Infrastructure/Verticals/Notifications/INotificationProvider.cs @@ -12,6 +12,8 @@ public interface INotificationProvider Task OnFailedImportStrike(FailedImportStrikeNotification notification); Task OnStalledStrike(StalledStrikeNotification notification); + + Task OnSlowStrike(SlowStrikeNotification notification); Task OnQueueItemDeleted(QueueItemDeletedNotification notification); diff --git a/code/Infrastructure/Verticals/Notifications/Models/SlowStrikeNotification.cs b/code/Infrastructure/Verticals/Notifications/Models/SlowStrikeNotification.cs new file mode 100644 index 00000000..796443bd --- /dev/null +++ b/code/Infrastructure/Verticals/Notifications/Models/SlowStrikeNotification.cs @@ -0,0 +1,5 @@ +namespace Infrastructure.Verticals.Notifications.Models; + +public sealed record SlowStrikeNotification : ArrNotification +{ +} \ No newline at end of file diff --git a/code/Infrastructure/Verticals/Notifications/Notifiarr/NotifiarrProvider.cs b/code/Infrastructure/Verticals/Notifications/Notifiarr/NotifiarrProvider.cs index 6ad8c1bc..66775d77 100644 --- a/code/Infrastructure/Verticals/Notifications/Notifiarr/NotifiarrProvider.cs +++ b/code/Infrastructure/Verticals/Notifications/Notifiarr/NotifiarrProvider.cs @@ -32,6 +32,11 @@ public class NotifiarrProvider : NotificationProvider await _proxy.SendNotification(BuildPayload(notification, WarningColor), _config); } + public override async Task OnSlowStrike(SlowStrikeNotification notification) + { + await _proxy.SendNotification(BuildPayload(notification, WarningColor), _config); + } + public override async Task OnQueueItemDeleted(QueueItemDeletedNotification notification) { await _proxy.SendNotification(BuildPayload(notification, ImportantColor), _config); diff --git a/code/Infrastructure/Verticals/Notifications/NotificationFactory.cs b/code/Infrastructure/Verticals/Notifications/NotificationFactory.cs index 10c5ba05..691d8079 100644 --- a/code/Infrastructure/Verticals/Notifications/NotificationFactory.cs +++ b/code/Infrastructure/Verticals/Notifications/NotificationFactory.cs @@ -24,6 +24,11 @@ public class NotificationFactory : INotificationFactory ActiveProviders() .Where(n => n.Config.OnStalledStrike) .ToList(); + + public List OnSlowStrikeEnabled() => + ActiveProviders() + .Where(n => n.Config.OnSlowStrike) + .ToList(); public List OnQueueItemDeletedEnabled() => ActiveProviders() diff --git a/code/Infrastructure/Verticals/Notifications/NotificationProvider.cs b/code/Infrastructure/Verticals/Notifications/NotificationProvider.cs index e1b6cc7b..c71bb3fe 100644 --- a/code/Infrastructure/Verticals/Notifications/NotificationProvider.cs +++ b/code/Infrastructure/Verticals/Notifications/NotificationProvider.cs @@ -18,6 +18,8 @@ public abstract class NotificationProvider : INotificationProvider public abstract Task OnFailedImportStrike(FailedImportStrikeNotification notification); public abstract Task OnStalledStrike(StalledStrikeNotification notification); + + public abstract Task OnSlowStrike(SlowStrikeNotification notification); public abstract Task OnQueueItemDeleted(QueueItemDeletedNotification notification); diff --git a/code/Infrastructure/Verticals/Notifications/NotificationPublisher.cs b/code/Infrastructure/Verticals/Notifications/NotificationPublisher.cs index 0577a963..68f9dea2 100644 --- a/code/Infrastructure/Verticals/Notifications/NotificationPublisher.cs +++ b/code/Infrastructure/Verticals/Notifications/NotificationPublisher.cs @@ -48,11 +48,16 @@ public class NotificationPublisher : INotificationPublisher switch (strikeType) { case StrikeType.Stalled: + case StrikeType.DownloadingMetadata: await _dryRunInterceptor.InterceptAsync(Notify, notification.Adapt()); break; case StrikeType.ImportFailed: await _dryRunInterceptor.InterceptAsync(Notify, notification.Adapt()); break; + case StrikeType.SlowSpeed: + case StrikeType.SlowTime: + await _dryRunInterceptor.InterceptAsync(Notify, notification.Adapt()); + break; } } catch (Exception ex) diff --git a/code/Infrastructure/Verticals/Notifications/NotificationService.cs b/code/Infrastructure/Verticals/Notifications/NotificationService.cs index fbe8fd60..4efadaac 100644 --- a/code/Infrastructure/Verticals/Notifications/NotificationService.cs +++ b/code/Infrastructure/Verticals/Notifications/NotificationService.cs @@ -44,6 +44,21 @@ public class NotificationService } } + public async Task Notify(SlowStrikeNotification notification) + { + foreach (INotificationProvider provider in _notificationFactory.OnSlowStrikeEnabled()) + { + try + { + await provider.OnSlowStrike(notification); + } + catch (Exception exception) + { + _logger.LogWarning(exception, "failed to send notification | provider {provider}", provider.Name); + } + } + } + public async Task Notify(QueueItemDeletedNotification notification) { foreach (INotificationProvider provider in _notificationFactory.OnQueueItemDeletedEnabled()) diff --git a/code/test/docker-compose.yml b/code/test/docker-compose.yml index d8a2be73..f249d236 100644 --- a/code/test/docker-compose.yml +++ b/code/test/docker-compose.yml @@ -262,12 +262,13 @@ services: - LIDARR__INSTANCES__0__URL=http://lidarr:8686 - LIDARR__INSTANCES__0__APIKEY=7f677cfdc074414397af53dd633860c5 - # - NOTIFIARR__ON_IMPORT_FAILED_STRIKE=true - # - NOTIFIARR__ON_STALLED_STRIKE=true - # - NOTIFIARR__ON_QUEUE_ITEM_DELETED=true - # - NOTIFIARR__ON_DOWNLOAD_CLEANED=true - # - NOTIFIARR__API_KEY=notifiarr_secret - # - NOTIFIARR__CHANNEL_ID=discord_channel_id + - NOTIFIARR__ON_IMPORT_FAILED_STRIKE=true + - NOTIFIARR__ON_STALLED_STRIKE=true + - NOTIFIARR__ON_SLOW_STRIKE=true + - NOTIFIARR__ON_QUEUE_ITEM_DELETED=true + - NOTIFIARR__ON_DOWNLOAD_CLEANED=true + - NOTIFIARR__API_KEY=notifiarr_secret + - NOTIFIARR__CHANNEL_ID=discord_channel_id volumes: - ./data/cleanuperr/logs:/var/logs - ./data/cleanuperr/ignored_downloads:/ignored diff --git a/variables.md b/variables.md index 7b1750c3..fa3a0302 100644 --- a/variables.md +++ b/variables.md @@ -675,7 +675,14 @@ - Required: No. #### **`NOTIFIARR__ON_STALLED_STRIKE`** -- Controls whether to notify when an item receives a stalled download strike. +- Controls whether to notify when an item receives a stalled download strike. This includes strikes for being stuck while downloading metadata. +- Type: Boolean +- Possible values: `true`, `false` +- Default: `false` +- Required: No. + +#### **`NOTIFIARR__ON_SLOW_STRIKE`** +- Controls whether to notify when an item receives a slow download strike. This includes strikes for having a low download speed or slow estimated finish time. - Type: Boolean - Possible values: `true`, `false` - Default: `false`