Remove reconnection attempts, return error unless ctrl+c was sent
This commit is contained in:
parent
4f91940047
commit
a1f5ce5d2b
17
main.go
17
main.go
|
@ -52,10 +52,10 @@ func main() {
|
||||||
tgEvents = make(chan GenericMessage, 5)
|
tgEvents = make(chan GenericMessage, 5)
|
||||||
logger = log.New(os.Stderr, "Main", log.Lmicroseconds)
|
logger = log.New(os.Stderr, "Main", log.Lmicroseconds)
|
||||||
sleeper = RealSleeper{time.Second * 60}
|
sleeper = RealSleeper{time.Second * 60}
|
||||||
stopRequested = atomic.Bool{}
|
cleanShutdown = atomic.Bool{}
|
||||||
)
|
)
|
||||||
|
|
||||||
stopRequested.Store(false)
|
cleanShutdown.Store(false)
|
||||||
config := MakeConfig(logger)
|
config := MakeConfig(logger)
|
||||||
|
|
||||||
s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration())
|
s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration())
|
||||||
|
@ -79,21 +79,20 @@ func main() {
|
||||||
tgSender, &wg, log.New(os.Stderr, "SendToTg", log.Lmicroseconds), tpl),
|
tgSender, &wg, log.New(os.Stderr, "SendToTg", log.Lmicroseconds), tpl),
|
||||||
)
|
)
|
||||||
|
|
||||||
go CloseSatelOnCtrlC(s, &stopRequested)
|
go CloseSatelOnCtrlC(s, &cleanShutdown)
|
||||||
|
|
||||||
for stopRequested.Load() == false {
|
|
||||||
for e := range FilterByTypeOrIndex(
|
for e := range FilterByTypeOrIndex(
|
||||||
FilterByLastSeen(s.Events, &wg, &dataStore, log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)),
|
FilterByLastSeen(s.Events, &wg, &dataStore, log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)),
|
||||||
&wg, config.AllowedTypes, config.AllowedIndexes) {
|
&wg, config.AllowedTypes, config.AllowedIndexes) {
|
||||||
logger.Print("Received change from SATEL: ", e)
|
logger.Print("Received change from SATEL: ", e)
|
||||||
tgEvents <- GenericMessage{e.BasicEvents}
|
tgEvents <- GenericMessage{e.BasicEvents}
|
||||||
}
|
}
|
||||||
if stopRequested.Load() == false {
|
|
||||||
logger.Printf("Waiting %d seconds before trying again", retryDelaySec)
|
|
||||||
time.Sleep(retryDelaySec * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
logger.Print("Closing...")
|
||||||
close(tgEvents)
|
close(tgEvents)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
if cleanShutdown.Load() {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,11 +94,11 @@ var SATEL_STRING_TO_CHANGE_TYPE = map[string]satel.ChangeType{
|
||||||
"zone-isolate": satel.ZoneIsolate,
|
"zone-isolate": satel.ZoneIsolate,
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseSatelOnCtrlC(s *satel.Satel, stopRequested *atomic.Bool) {
|
func CloseSatelOnCtrlC(s *satel.Satel, cleanShutdown *atomic.Bool) {
|
||||||
exitSignal := make(chan os.Signal, 1)
|
exitSignal := make(chan os.Signal, 1)
|
||||||
signal.Notify(exitSignal, os.Interrupt)
|
signal.Notify(exitSignal, os.Interrupt)
|
||||||
<-exitSignal
|
<-exitSignal
|
||||||
stopRequested.Store(true)
|
cleanShutdown.Store(true)
|
||||||
s.Close()
|
s.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue