capture errors

This commit is contained in:
kiwiidb
2023-02-20 14:36:17 +01:00
parent 945d936146
commit 97fc22aa7d
2 changed files with 17 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ import (
"sync" "sync"
"github.com/getAlby/lndhub.go/db/models" "github.com/getAlby/lndhub.go/db/models"
"github.com/getsentry/sentry-go"
amqp "github.com/rabbitmq/amqp091-go" amqp "github.com/rabbitmq/amqp091-go"
) )
@@ -65,27 +66,33 @@ func (svc *LndhubService) StartRabbitMqPublisher(ctx context.Context) error {
case <-ctx.Done(): case <-ctx.Done():
return context.Canceled return context.Canceled
case incoming := <-incomingInvoices: case incoming := <-incomingInvoices:
svc.publishInvoice(ctx, incoming, ch) err = svc.publishInvoice(ctx, incoming, ch)
if err != nil {
svc.Logger.Error(err)
sentry.CaptureException(err)
}
case outgoing := <-outgoingInvoices: case outgoing := <-outgoingInvoices:
svc.publishInvoice(ctx, outgoing, ch) err = svc.publishInvoice(ctx, outgoing, ch)
if err != nil {
svc.Logger.Error(err)
sentry.CaptureException(err)
}
} }
} }
} }
func (svc *LndhubService) publishInvoice(ctx context.Context, invoice models.Invoice, ch *amqp.Channel) { func (svc *LndhubService) publishInvoice(ctx context.Context, invoice models.Invoice, ch *amqp.Channel) error {
key := fmt.Sprintf("invoice.%s.%s", invoice.Type, invoice.State) key := fmt.Sprintf("invoice.%s.%s", invoice.Type, invoice.State)
user, err := svc.FindUser(context.Background(), invoice.UserID) user, err := svc.FindUser(context.Background(), invoice.UserID)
if err != nil { if err != nil {
svc.Logger.Error(err) return err
return
} }
payload := bufPool.Get().(*bytes.Buffer) payload := bufPool.Get().(*bytes.Buffer)
err = json.NewEncoder(payload).Encode(convertPayload(invoice, user)) err = json.NewEncoder(payload).Encode(convertPayload(invoice, user))
if err != nil { if err != nil {
svc.Logger.Error(err) return err
return
} }
err = ch.PublishWithContext(ctx, err = ch.PublishWithContext(ctx,
@@ -99,8 +106,8 @@ func (svc *LndhubService) publishInvoice(ctx context.Context, invoice models.Inv
}, },
) )
if err != nil { if err != nil {
svc.Logger.Error(err) return err
return
} }
svc.Logger.Debugf("Succesfully published invoice to rabbitmq with RHash %s", invoice.RHash) svc.Logger.Debugf("Succesfully published invoice to rabbitmq with RHash %s", invoice.RHash)
return nil
} }

View File

@@ -216,6 +216,7 @@ func main() {
svc.Logger.Error(err) svc.Logger.Error(err)
sentry.CaptureException(err) sentry.CaptureException(err)
} }
svc.Logger.Info("Rabbit routine done")
backgroundWg.Done() backgroundWg.Done()
}() }()
} }