try to better respect event ordering

This commit is contained in:
nicolas.dorier
2018-05-06 02:06:07 +09:00
parent 5f05ca5ac6
commit 272ac49872
2 changed files with 11 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>1.0.2.5</Version> <Version>1.0.2.6</Version>
<NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn> <NoWarn>NU1701,CA1816,CA1308,CA1810,CA2208</NoWarn>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -305,7 +305,10 @@ namespace BTCPayServer.HostedServices
leases.Add(_EventAggregator.Subscribe<InvoiceEvent>(async e => leases.Add(_EventAggregator.Subscribe<InvoiceEvent>(async e =>
{ {
var invoice = await _InvoiceRepository.GetInvoice(null, e.InvoiceId); var invoice = await _InvoiceRepository.GetInvoice(null, e.InvoiceId);
await SaveEvent(invoice.Id, e); List<Task> tasks = new List<Task>();
// Awaiting this later help make sure invoices should arrive in order
tasks.Add(SaveEvent(invoice.Id, e));
// we need to use the status in the event and not in the invoice. The invoice might now be in another status. // we need to use the status in the event and not in the invoice. The invoice might now be in another status.
if (invoice.FullNotifications) if (invoice.FullNotifications)
@@ -315,20 +318,22 @@ namespace BTCPayServer.HostedServices
e.Name == "invoice_failedToConfirm" || e.Name == "invoice_failedToConfirm" ||
e.Name == "invoice_markedInvalid" || e.Name == "invoice_markedInvalid" ||
e.Name == "invoice_failedToConfirm" || e.Name == "invoice_failedToConfirm" ||
e.Name == "invoice_completed" e.Name == "invoice_completed" ||
e.Name == "invoice_expiredPaidPartial"
) )
await Notify(invoice); tasks.Add(Notify(invoice));
} }
if (e.Name == "invoice_confirmed") if (e.Name == "invoice_confirmed")
{ {
await Notify(invoice); tasks.Add(Notify(invoice));
} }
if (invoice.ExtendedNotifications) if (invoice.ExtendedNotifications)
{ {
await Notify(invoice, e.EventCode, e.Name); tasks.Add(Notify(invoice, e.EventCode, e.Name));
} }
await Task.WhenAll(tasks.ToArray());
})); }));