dispose streamer properly

This commit is contained in:
Kukks
2019-01-14 08:21:27 +01:00
parent abcd2c1750
commit f2630df387
5 changed files with 24 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Controllers; using BTCPayServer.Controllers;
using BTCPayServer.Crowdfund;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Events; using BTCPayServer.Events;
using BTCPayServer.Hubs; using BTCPayServer.Hubs;

View File

@@ -6,6 +6,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Crowdfund;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Filters; using BTCPayServer.Filters;
using BTCPayServer.Hubs; using BTCPayServer.Hubs;

View File

@@ -2,11 +2,11 @@ using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Controllers; using BTCPayServer.Controllers;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Events; using BTCPayServer.Events;
using BTCPayServer.Hubs;
using BTCPayServer.Models.AppViewModels; using BTCPayServer.Models.AppViewModels;
using BTCPayServer.Payments; using BTCPayServer.Payments;
using BTCPayServer.Rating; using BTCPayServer.Rating;
@@ -16,14 +16,11 @@ using BTCPayServer.Services.Rates;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using NBitcoin; using NBitcoin;
using YamlDotNet.Core;
namespace BTCPayServer.Hubs namespace BTCPayServer.Crowdfund
{ {
public class public class CrowdfundHubStreamer: IDisposable
CrowdfundHubStreamer
{ {
public const string CrowdfundInvoiceOrderIdPrefix = "crowdfund-app_"; public const string CrowdfundInvoiceOrderIdPrefix = "crowdfund-app_";
private readonly EventAggregator _EventAggregator; private readonly EventAggregator _EventAggregator;
@@ -38,6 +35,8 @@ namespace BTCPayServer.Hubs
private readonly ConcurrentDictionary<string,(string appId, bool useAllStoreInvoices,bool useInvoiceAmount)> _QuickAppInvoiceLookup = private readonly ConcurrentDictionary<string,(string appId, bool useAllStoreInvoices,bool useInvoiceAmount)> _QuickAppInvoiceLookup =
new ConcurrentDictionary<string, (string appId, bool useAllStoreInvoices, bool useInvoiceAmount)>(); new ConcurrentDictionary<string, (string appId, bool useAllStoreInvoices, bool useInvoiceAmount)>();
private List<IEventAggregatorSubscription> _Subscriptions;
public CrowdfundHubStreamer(EventAggregator eventAggregator, public CrowdfundHubStreamer(EventAggregator eventAggregator,
IHubContext<CrowdfundHub> hubContext, IHubContext<CrowdfundHub> hubContext,
IMemoryCache memoryCache, IMemoryCache memoryCache,
@@ -116,13 +115,15 @@ namespace BTCPayServer.Hubs
private void SubscribeToEvents() private void SubscribeToEvents()
{ {
_Subscriptions = new List<IEventAggregatorSubscription>()
_EventAggregator.Subscribe<InvoiceEvent>(OnInvoiceEvent);
_EventAggregator.Subscribe<AppsController.CrowdfundAppUpdated>(updated =>
{ {
UpdateLookup(updated.AppId, updated.StoreId, updated.Settings); _EventAggregator.Subscribe<InvoiceEvent>(OnInvoiceEvent),
InvalidateCacheForApp(updated.AppId); _EventAggregator.Subscribe<AppsController.CrowdfundAppUpdated>(updated =>
}); {
UpdateLookup(updated.AppId, updated.StoreId, updated.Settings);
InvalidateCacheForApp(updated.AppId);
})
};
} }
private string GetCacheKey(string appId) private string GetCacheKey(string appId)
@@ -361,5 +362,10 @@ namespace BTCPayServer.Hubs
StartDate = startDate StartDate = startDate
}); });
} }
public void Dispose()
{
_Subscriptions.ForEach(subscription => subscription.Dispose());
}
} }
} }

View File

@@ -38,6 +38,7 @@ using BTCPayServer.Logging;
using BTCPayServer.HostedServices; using BTCPayServer.HostedServices;
using Meziantou.AspNetCore.BundleTagHelpers; using Meziantou.AspNetCore.BundleTagHelpers;
using System.Security.Claims; using System.Security.Claims;
using BTCPayServer.Crowdfund;
using BTCPayServer.Hubs; using BTCPayServer.Hubs;
using BTCPayServer.Payments.Changelly; using BTCPayServer.Payments.Changelly;
using BTCPayServer.Payments.Lightning; using BTCPayServer.Payments.Lightning;

View File

@@ -1,4 +1,5 @@
@using BTCPayServer.Hubs @using BTCPayServer.Crowdfund
@using BTCPayServer.Hubs
@addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers @addTagHelper *, Meziantou.AspNetCore.BundleTagHelpers
@model UpdateCrowdfundViewModel @model UpdateCrowdfundViewModel
@{ @{