1
0
Fork 0

Remove reconnection attempts, return error unless ctrl+c was sent

This commit is contained in:
Michał Rudowicz 2024-03-30 07:21:37 +01:00
parent 4f91940047
commit a1f5ce5d2b
2 changed files with 15 additions and 16 deletions

27
main.go
View File

@ -52,10 +52,10 @@ func main() {
tgEvents = make(chan GenericMessage, 5)
logger = log.New(os.Stderr, "Main", log.Lmicroseconds)
sleeper = RealSleeper{time.Second * 60}
stopRequested = atomic.Bool{}
cleanShutdown = atomic.Bool{}
)
stopRequested.Store(false)
cleanShutdown.Store(false)
config := MakeConfig(logger)
s := makeSatel(config.SatelAddr, config.PoolInterval.GetDuration())
@ -79,21 +79,20 @@ func main() {
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(
FilterByLastSeen(s.Events, &wg, &dataStore, log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)),
&wg, config.AllowedTypes, config.AllowedIndexes) {
logger.Print("Received change from SATEL: ", e)
tgEvents <- GenericMessage{e.BasicEvents}
}
if stopRequested.Load() == false {
logger.Printf("Waiting %d seconds before trying again", retryDelaySec)
time.Sleep(retryDelaySec * time.Second)
}
for e := range FilterByTypeOrIndex(
FilterByLastSeen(s.Events, &wg, &dataStore, log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)),
&wg, config.AllowedTypes, config.AllowedIndexes) {
logger.Print("Received change from SATEL: ", e)
tgEvents <- GenericMessage{e.BasicEvents}
}
logger.Print("Closing...")
close(tgEvents)
wg.Wait()
if cleanShutdown.Load() {
os.Exit(0)
}
os.Exit(1)
}

View File

@ -94,11 +94,11 @@ var SATEL_STRING_TO_CHANGE_TYPE = map[string]satel.ChangeType{
"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)
signal.Notify(exitSignal, os.Interrupt)
<-exitSignal
stopRequested.Store(true)
cleanShutdown.Store(true)
s.Close()
}