From 38803b32a867e8476844542cdd72d4cda0b2485d Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 31 May 2024 18:30:02 -0500 Subject: [PATCH] fixup! fixup! wip: Notifications support through Apprise --- .../NotificationService.cs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Recyclarr.Notifications/NotificationService.cs b/src/Recyclarr.Notifications/NotificationService.cs index 4d3aefff..952c3618 100644 --- a/src/Recyclarr.Notifications/NotificationService.cs +++ b/src/Recyclarr.Notifications/NotificationService.cs @@ -1,6 +1,7 @@ using System.Diagnostics.Metrics; using System.Text; using Flurl.Http; +using Recyclarr.Common.Extensions; using Recyclarr.Http; using Recyclarr.Notifications.Apprise; using Recyclarr.Notifications.Apprise.Dto; @@ -83,9 +84,28 @@ public sealed class NotificationService( public sealed class NotificationScope : IDisposable { - public NotificationScope(MeterListener meterListener) + private readonly MeterListener _meterListener = new(); + + public NotificationScope() + { + _meterListener.InstrumentPublished = (instrument, listener) => + { + if (instrument.Meter.Name.StartsWithIgnoreCase("recyclarr.")) + { + listener.EnableMeasurementEvents(instrument); + } + }; + + _meterListener.SetMeasurementEventCallback(OnMeasurementRecorded); + } + + private void OnMeasurementRecorded( + Instrument instrument, + int measurement, + ReadOnlySpan> tags, + object? state) { - // var meter = meterFactory.Create(instanceName); + throw new NotImplementedException(); } public void ObtainCapturedMetrics() @@ -96,6 +116,6 @@ public sealed class NotificationScope : IDisposable public void Dispose() { - // TODO + _meterListener.Dispose(); } }