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
|
# Files with secrets
|
||||||
*secret*
|
*secret*
|
||||||
tmp/
|
tmp/
|
||||||
|
@ -35,7 +35,7 @@ func init() {
|
|||||||
discoveryStorage.LogChannel = make(chan string)
|
discoveryStorage.LogChannel = make(chan string)
|
||||||
discoveryStorage.TTL = config.TTL
|
discoveryStorage.TTL = config.TTL
|
||||||
|
|
||||||
// localhost initization
|
// localhost initiation
|
||||||
localHost = server.LocalHost{
|
localHost = server.LocalHost{
|
||||||
LabelsPath: config.LabelsPath,
|
LabelsPath: config.LabelsPath,
|
||||||
HostnameOverride: config.HostName,
|
HostnameOverride: config.HostName,
|
||||||
|
@ -3,7 +3,9 @@ package nats_driver
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/by-cx/lobby/common"
|
"github.com/by-cx/lobby/common"
|
||||||
"github.com/by-cx/lobby/server"
|
"github.com/by-cx/lobby/server"
|
||||||
@ -53,13 +55,20 @@ func (d *Driver) Init() error {
|
|||||||
return fmt.Errorf("please initiate LogChannel variable")
|
return fmt.Errorf("please initiate LogChannel variable")
|
||||||
}
|
}
|
||||||
|
|
||||||
nc, err := nats.Connect(d.NATSUrl)
|
var nc *nats.Conn
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
d.nc = nc
|
|
||||||
|
|
||||||
_, 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user