Skip to content

Commit

Permalink
Merge pull request #12 from getAlby/feature/config-rmq-timeout
Browse files Browse the repository at this point in the history
make rmq timeout config & increase default
  • Loading branch information
kiwiidb authored Jul 25, 2023
2 parents 21b7cf6 + 14d44b5 commit 09ac45f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func TestInvoicePublish(t *testing.T) {
svc, mlnd, m := createTestService(t, cfg, LNDInvoiceExchange, LNDInvoiceRoutingKey)
ctx, cancel := context.WithCancel(context.Background())
go func() {
err := svc.startInvoiceSubscription(ctx)
assert.EqualError(t, err, context.Canceled.Error())
svc.startInvoiceSubscription(ctx)
}()
// - mock incoming invoice
// the new invoice that will be saved will have addIndex + 1
Expand All @@ -97,8 +96,9 @@ func TestInvoicePublish(t *testing.T) {
}
func TestPaymentPublish(t *testing.T) {
cfg := &Config{
DatabaseUri: os.Getenv("DATABASE_URI"),
RabbitMQUri: os.Getenv("RABBITMQ_URI"),
DatabaseUri: os.Getenv("DATABASE_URI"),
RabbitMQUri: os.Getenv("RABBITMQ_URI"),
RabbitMQTimeoutSeconds: 1,
}
svc, mlnd, m := createTestService(t, cfg, LNDPaymentExchange, "payment.outgoing.*")
defer svc.db.Exec("delete from payments;")
Expand Down
3 changes: 2 additions & 1 deletion service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config struct {
DatabaseMaxIdleConns int `envconfig:"DATABASE_MAX_IDLE_CONNS" default:"5"`
DatabaseConnMaxLifetime int `envconfig:"DATABASE_CONN_MAX_LIFETIME" default:"1800"` // 30 minutes
RabbitMQUri string `envconfig:"RABBITMQ_URI" required:"true"`
RabbitMQTimeoutSeconds int `envconfig:"RABBITMQ_TIMEOUT_SECONDS" default:"10"`
SentryDSN string `envconfig:"SENTRY_DSN"`
}

Expand Down Expand Up @@ -349,7 +350,7 @@ func (svc *Service) PublishPayload(ctx context.Context, payload interface{}, exc
return err
}

timeoutCtx, cancel := context.WithTimeout(ctx, 3*time.Second)
timeoutCtx, cancel := context.WithTimeout(ctx, time.Duration(svc.cfg.RabbitMQTimeoutSeconds)*time.Second)
defer cancel()
logrus.Info("Publishing message")
conf, err := svc.rabbitChannel.PublishWithDeferredConfirmWithContext(
Expand Down

0 comments on commit 09ac45f

Please sign in to comment.