Reconnect instead of exit when NATS is not available
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0e836b68a8
commit
55b3376d4c
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
.history/
|
||||
|
||||
# Files with secrets
|
||||
*secret*
|
||||
tmp/
|
||||
|
@ -35,7 +35,7 @@ func init() {
|
||||
discoveryStorage.LogChannel = make(chan string)
|
||||
discoveryStorage.TTL = config.TTL
|
||||
|
||||
// localhost initization
|
||||
// localhost initiation
|
||||
localHost = server.LocalHost{
|
||||
LabelsPath: config.LabelsPath,
|
||||
HostnameOverride: config.HostName,
|
||||
|
@ -3,7 +3,9 @@ package nats_driver
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/by-cx/lobby/common"
|
||||
"github.com/by-cx/lobby/server"
|
||||
@ -53,13 +55,20 @@ func (d *Driver) Init() error {
|
||||
return fmt.Errorf("please initiate LogChannel variable")
|
||||
}
|
||||
|
||||
nc, err := nats.Connect(d.NATSUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.nc = nc
|
||||
var nc *nats.Conn
|
||||
|
||||
_, err = nc.Subscribe(d.NATSDiscoveryChannel, d.handler)
|
||||
for {
|
||||
nc, err := nats.Connect(d.NATSUrl)
|
||||
if err != nil {
|
||||
log.Println("Can't connect to the NATS server, waiting for 5 seconds before I try it again.")
|
||||
time.Sleep(time.Second * 5)
|
||||
continue
|
||||
}
|
||||
d.nc = nc
|
||||
break
|
||||
}
|
||||
|
||||
_, err := nc.Subscribe(d.NATSDiscoveryChannel, d.handler)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user