1
0
mirror of https://github.com/bgp/stayrtr.git synced 2024-05-06 15:54:54 +00:00

Catch error and simplify the initial sync stuff

This commit is contained in:
Null User
2021-10-27 04:36:47 +00:00
parent 2455723c87
commit 5878317f6e

View File

@ -377,19 +377,14 @@ func (s *state) routineUpdate(file string, interval int, slurmFile string) {
log.Debugf("Starting refresh routine (file: %v, interval: %vs, slurm: %v)", file, interval, slurmFile)
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGHUP)
lastUpdateFail := false
for {
var delay *time.Timer
if (s.lastchange.IsZero()) {
log.Warn("Initial sync not complete. Refreshing every 30 seconds")
delay = time.NewTimer(time.Duration(30) * time.Second)
} else if (lastUpdateFail) {
log.Warn("Update failure causing 30 second refresh")
delay = time.NewTimer(time.Duration(30) * time.Second)
} else {
delay = time.NewTimer(time.Duration(interval) * time.Second)
}
lastUpdateFail = false
select {
case <-delay.C:
case <-signals:
@ -431,7 +426,6 @@ func (s *state) routineUpdate(file string, interval int, slurmFile string) {
err := s.updateFromNewState()
if err != nil {
log.Errorf("Error updating from new state: %v", err)
lastUpdateFail = true
}
}
}
@ -605,7 +599,10 @@ func run() error {
}
// Initial calculation of state (after fetching cache + slurm)
s.updateFromNewState()
err = s.updateFromNewState()
if err != nil {
log.Warnf("Error setting up intial state: %s", err)
}
if *Bind != "" {
go func() {