mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Make sure the process doesn't crash if exception raised in Subscribe
This commit is contained in:
@@ -665,9 +665,9 @@ namespace BTCPayServer.Controllers
|
|||||||
CompositeDisposable leases = new CompositeDisposable();
|
CompositeDisposable leases = new CompositeDisposable();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
leases.Add(_EventAggregator.Subscribe<Events.InvoiceDataChangedEvent>(async o => await NotifySocket(webSocket, o.InvoiceId, invoiceId)));
|
leases.Add(_EventAggregator.SubscribeAsync<Events.InvoiceDataChangedEvent>(async o => await NotifySocket(webSocket, o.InvoiceId, invoiceId)));
|
||||||
leases.Add(_EventAggregator.Subscribe<Events.InvoiceNewPaymentDetailsEvent>(async o => await NotifySocket(webSocket, o.InvoiceId, invoiceId)));
|
leases.Add(_EventAggregator.SubscribeAsync<Events.InvoiceNewPaymentDetailsEvent>(async o => await NotifySocket(webSocket, o.InvoiceId, invoiceId)));
|
||||||
leases.Add(_EventAggregator.Subscribe<Events.InvoiceEvent>(async o => await NotifySocket(webSocket, o.Invoice.Id, invoiceId)));
|
leases.Add(_EventAggregator.SubscribeAsync<Events.InvoiceEvent>(async o => await NotifySocket(webSocket, o.Invoice.Id, invoiceId)));
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var message = await webSocket.ReceiveAndPingAsync(DummyBuffer, default(CancellationToken));
|
var message = await webSocket.ReceiveAndPingAsync(DummyBuffer, default(CancellationToken));
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace BTCPayServer.Controllers
|
|||||||
IEventAggregatorSubscription subscription = null;
|
IEventAggregatorSubscription subscription = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
subscription = _eventAggregator.Subscribe<UserNotificationsUpdatedEvent>(async evt =>
|
subscription = _eventAggregator.SubscribeAsync<UserNotificationsUpdatedEvent>(async evt =>
|
||||||
{
|
{
|
||||||
if (evt.UserId == userId)
|
if (evt.UserId == userId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -145,6 +145,10 @@ namespace BTCPayServer
|
|||||||
return Subscribe(new Action<IEventAggregatorSubscription, T>((sub, t) => subscription(sub, t)));
|
return Subscribe(new Action<IEventAggregatorSubscription, T>((sub, t) => subscription(sub, t)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEventAggregatorSubscription SubscribeAsync<T>(Func<T, Task> subscription)
|
||||||
|
{
|
||||||
|
return Subscribe(new Action<IEventAggregatorSubscription, T>((sub, t) => _ = subscription(t)));
|
||||||
|
}
|
||||||
public IEventAggregatorSubscription Subscribe<T>(Action<T> subscription)
|
public IEventAggregatorSubscription Subscribe<T>(Action<T> subscription)
|
||||||
{
|
{
|
||||||
return Subscribe(new Action<IEventAggregatorSubscription, T>((sub, t) => subscription(t)));
|
return Subscribe(new Action<IEventAggregatorSubscription, T>((sub, t) => subscription(t)));
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
readonly CompositeDisposable leases = new CompositeDisposable();
|
readonly CompositeDisposable leases = new CompositeDisposable();
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
leases.Add(_EventAggregator.Subscribe<InvoiceEvent>(async e =>
|
leases.Add(_EventAggregator.SubscribeAsync<InvoiceEvent>(async e =>
|
||||||
{
|
{
|
||||||
if (e.EventCode == InvoiceEventCode.PaymentSettled)
|
if (e.EventCode == InvoiceEventCode.PaymentSettled)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
Watch(b.InvoiceId);
|
Watch(b.InvoiceId);
|
||||||
}));
|
}));
|
||||||
leases.Add(_eventAggregator.Subscribe<Events.InvoiceEvent>(async b =>
|
leases.Add(_eventAggregator.SubscribeAsync<Events.InvoiceEvent>(async b =>
|
||||||
{
|
{
|
||||||
if (InvoiceEventNotification.HandlesEvent(b.Name))
|
if (InvoiceEventNotification.HandlesEvent(b.Name))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
{
|
{
|
||||||
_RunningTask = new TaskCompletionSource<bool>();
|
_RunningTask = new TaskCompletionSource<bool>();
|
||||||
_Cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
_Cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||||
leases.Add(_Aggregator.Subscribe<Events.NBXplorerStateChangedEvent>(async nbxplorerEvent =>
|
leases.Add(_Aggregator.SubscribeAsync<Events.NBXplorerStateChangedEvent>(async nbxplorerEvent =>
|
||||||
{
|
{
|
||||||
if (nbxplorerEvent.NewState == NBXplorerState.Ready)
|
if (nbxplorerEvent.NewState == NBXplorerState.Ready)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
readonly CompositeDisposable leases = new CompositeDisposable();
|
readonly CompositeDisposable leases = new CompositeDisposable();
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
leases.Add(_Aggregator.Subscribe<Events.InvoiceEvent>(async inv =>
|
leases.Add(_Aggregator.SubscribeAsync<Events.InvoiceEvent>(async inv =>
|
||||||
{
|
{
|
||||||
if (inv.Name == InvoiceEvent.Created)
|
if (inv.Name == InvoiceEvent.Created)
|
||||||
{
|
{
|
||||||
@@ -159,7 +159,7 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
leases.Add(_Aggregator.Subscribe<Events.InvoiceDataChangedEvent>(async inv =>
|
leases.Add(_Aggregator.SubscribeAsync<Events.InvoiceDataChangedEvent>(async inv =>
|
||||||
{
|
{
|
||||||
if (inv.State.Status == InvoiceStatusLegacy.New &&
|
if (inv.State.Status == InvoiceStatusLegacy.New &&
|
||||||
inv.State.ExceptionStatus == InvoiceExceptionStatus.PaidPartial)
|
inv.State.ExceptionStatus == InvoiceExceptionStatus.PaidPartial)
|
||||||
|
|||||||
Reference in New Issue
Block a user