mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-21 14:44:45 +01:00
payment finalizer: never break loop
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/getAlby/lndhub.go/db/models"
|
"github.com/getAlby/lndhub.go/db/models"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
@@ -167,33 +166,13 @@ func (client *DefaultClient) FinalizeInitializedPayments(ctx context.Context, sv
|
|||||||
|
|
||||||
client.logger.Infof("Payment finalizer: Found %d pending invoices", len(pendingInvoices))
|
client.logger.Infof("Payment finalizer: Found %d pending invoices", len(pendingInvoices))
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Hour)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
client.logger.Info("Starting payment finalizer rabbitmq consumer")
|
client.logger.Info("Starting payment finalizer rabbitmq consumer")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Shortcircuit if no pending invoices are left
|
|
||||||
if len(pendingInvoices) == 0 {
|
|
||||||
client.logger.Info("Payment finalizer: Resolved all pending payments, exiting payment finalizer routine")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return context.Canceled
|
return context.Canceled
|
||||||
|
|
||||||
case <-ticker.C:
|
|
||||||
invoices, err := getInvoicesTable(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingInvoices = invoices
|
|
||||||
|
|
||||||
client.logger.Infof("Payment finalizer: Found %d pending invoices", len(pendingInvoices))
|
|
||||||
|
|
||||||
case delivery, ok := <-deliveryChan:
|
case delivery, ok := <-deliveryChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user