Check if it's time for refresh before refreshing

master
Elis Hirwing 5 years ago
parent 2e8dd49a56
commit 79a1693942
Signed by: etu
GPG Key ID: D57EFA625C9A925F
  1. 2
      src/statusscreen/Config.go
  2. 22
      src/statusscreen/SL.go

@ -4,7 +4,7 @@ package statusscreen
type Config struct {
SL struct {
APIKey string
RefreshDelay int
RefreshDelay int64
SiteID int
APIURL string
}

@ -54,16 +54,20 @@ func (sl *SL) GetOutput() string {
"Expcted",
})
sldata, err := sl.getTimeTable()
// If no error occured, save the latest data to the struct
if err == nil {
sl.lastResponse = sldata
sl.lastRefresh = time.Now().Unix()
}
// Check if it's time to refresh yet
if (sl.lastRefresh + sl.Config.SL.RefreshDelay) <= time.Now().Unix() {
// If it is, refresh
sldata, err := sl.getTimeTable()
// If no error occured, save the latest data to the struct
if err == nil {
sl.lastResponse = sldata
sl.lastRefresh = time.Now().Unix()
}
if err != nil {
log.Fatal(err)
if err != nil {
log.Fatal(err)
}
}
for _, v := range sl.lastResponse.ResponseData.Metros {

Loading…
Cancel
Save