From 72e1be8944faa8ec9413c4308be81be1b079e815 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 23 Jun 2022 12:46:59 +0200 Subject: [PATCH] main.go: in readerLoop() add a counter and sent to telegram if we try connecting more than 3 times. --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 40cf488..07179ee 100644 --- a/main.go +++ b/main.go @@ -38,14 +38,25 @@ const RS_READ = 2 func readerLoop() { state := RS_CONNECT + var recon_cnt uint = 0 for { switch state { 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) if err != nil { 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 ....") time.Sleep(5 * time.Second) break; @@ -60,6 +71,7 @@ func readerLoop() { // Connected log.Printf("Connected, Start: %d, End: %d", shClient.StartBlock, shClient.EndBlock) state = RS_READ + recon_cnt = 0 case RS_READ : err := shClient.Read() if err != nil {