Skip to content

Commit

Permalink
Delay reconnect log (#2636)
Browse files Browse the repository at this point in the history
* delay logging of reconnect msg to 1 second

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* add changelog

Signed-off-by: jkoberg <jkoberg@owncloud.com>

* address TODO

Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj authored Mar 15, 2022
1 parent d008faf commit 6a598b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/delay-reconnect-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: delay reconnect log for events

Print reconnect information log only when reconnect time is bigger than a second

https://github.com/cs3org/reva/pull/2636
9 changes: 5 additions & 4 deletions pkg/events/server/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
package server

import (
"fmt"
"time"

"github.com/asim/go-micro/plugins/events/nats/v4"
"github.com/cenkalti/backoff"
"github.com/cs3org/reva/v2/pkg/logger"
"go-micro.dev/v4/events"

stanServer "github.com/nats-io/nats-streaming-server/server"
Expand All @@ -46,10 +47,10 @@ func NewNatsStream(opts ...nats.Option) (events.Stream, error) {
b := backoff.NewExponentialBackOff()
var stream events.Stream
o := func() error {
n := b.NextBackOff()
s, err := nats.NewStream(opts...)
if err != nil {
// TODO: should we get the standard logger here? if yes: How?
fmt.Printf("can't connect to nats (stan) server, retrying in %s\n", b.NextBackOff())
if err != nil && n > time.Second {
logger.New().Error().Err(err).Msgf("can't connect to nats (stan) server, retrying in %s", n)
}
stream = s
return err
Expand Down

0 comments on commit 6a598b8

Please sign in to comment.