Browse Source

Check if it's time for refresh before refreshing

master
Elis Hirwing 2 years ago
parent
commit
79a1693942
Signed by: etu <elis@hirwing.se> GPG Key ID: D57EFA625C9A925F
2 changed files with 14 additions and 10 deletions
  1. +1
    -1
      src/statusscreen/Config.go
  2. +13
    -9
      src/statusscreen/SL.go

+ 1
- 1
src/statusscreen/Config.go View File

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


+ 13
- 9
src/statusscreen/SL.go View File

@@ -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