Skip to content

Commit

Permalink
Make periodic reconnection optional, defaults to false
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan McCall committed Apr 4, 2018
1 parent 4c3815d commit d2d0c87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type StatsdClient struct {
eventStringTpl string
Logger Logger
conn_type string
reconnect bool
reconnect_ticker *time.Ticker
}

Expand All @@ -58,14 +59,17 @@ func NewStatsdClient(addr string, prefix string) *StatsdClient {
prefix: prefix,
Logger: log.New(os.Stdout, "[StatsdClient] ", log.Ldate|log.Ltime),
eventStringTpl: "%s%s:%s",
reconnect: false,
reconnect_ticker: time.NewTicker(30 * time.Second),
}

go func() {
for range client.reconnect_ticker.C {
err := client.Reconnect()
if err != nil {
fmt.Println(err)
if client.reconnect {
err := client.Reconnect()
if err != nil {
fmt.Println(err)
}
}
}
}()
Expand Down
1 change: 1 addition & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func TestReconnecting(t *testing.T) {
prefix := "test."

client := NewStatsdClient(udpAddr.String(), prefix)
client.reconnect = true
client.reconnect_ticker = time.NewTicker(10 * time.Millisecond)

ch := make(chan string, 0)
Expand Down

0 comments on commit d2d0c87

Please sign in to comment.