mirror of
https://github.com/bgp/stayrtr.git
synced 2024-05-06 15:54:54 +00:00
Make the refresh faster when update fails
This commit is contained in:
@ -377,12 +377,19 @@ 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 {
|
||||
delay := time.NewTimer(time.Duration(interval) * time.Second)
|
||||
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:
|
||||
@ -424,6 +431,7 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user