mirror of
https://github.com/eosswedenorg/thalos
synced 2026-07-04 12:03:41 +02:00
main.go: in readerLoop() add a counter and sent to telegram if we try connecting more than 3 times.
This commit is contained in:
parent
9a3dac391e
commit
72e1be8944
1 changed files with 13 additions and 1 deletions
14
main.go
14
main.go
|
|
@ -38,14 +38,25 @@ const RS_READ = 2
|
||||||
func readerLoop() {
|
func readerLoop() {
|
||||||
|
|
||||||
state := RS_CONNECT
|
state := RS_CONNECT
|
||||||
|
var recon_cnt uint = 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
switch state {
|
switch state {
|
||||||
case RS_CONNECT :
|
case RS_CONNECT :
|
||||||
log.Printf("Connecting to ship at: %s", conf.ShipApi)
|
recon_cnt++
|
||||||
|
log.Printf("Connecting to ship at: %s (Try %d)", conf.ShipApi, recon_cnt)
|
||||||
err := shClient.Connect(conf.ShipApi)
|
err := shClient.Connect(conf.ShipApi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
||||||
|
if recon_cnt >= 3 {
|
||||||
|
msg := fmt.Sprintf("Failed to connect to ship at '%s'", conf.ShipApi)
|
||||||
|
if err = telegram.Send(msg); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
recon_cnt = 0
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("Trying again in 5 seconds ....")
|
log.Printf("Trying again in 5 seconds ....")
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
break;
|
break;
|
||||||
|
|
@ -60,6 +71,7 @@ func readerLoop() {
|
||||||
// Connected
|
// Connected
|
||||||
log.Printf("Connected, Start: %d, End: %d", shClient.StartBlock, shClient.EndBlock)
|
log.Printf("Connected, Start: %d, End: %d", shClient.StartBlock, shClient.EndBlock)
|
||||||
state = RS_READ
|
state = RS_READ
|
||||||
|
recon_cnt = 0
|
||||||
case RS_READ :
|
case RS_READ :
|
||||||
err := shClient.Read()
|
err := shClient.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue