Retrieve data every minute

This commit is contained in:
Nise Void 2018-05-14 12:49:54 +02:00
parent 2c4366ff1f
commit bfee747b17
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3

18
main.go
View File

@ -19,10 +19,9 @@ var db *qbdb.DB
func main() { func main() {
initDB() initDB()
startDate := GetStartDate() start := GetStartDate()
for {
for time.Now().After(startDate) { end := start.Add(time.Hour)
start, end := startDate, startDate.AddDate(0, 0, 7)
data := GetFortopData(start, end) data := GetFortopData(start, end)
ranges := map[string][]Range{} ranges := map[string][]Range{}
@ -46,7 +45,14 @@ func main() {
insertSets(sets) insertSets(sets)
startDate = end if end.Before(time.Now()) {
start = end.Add(time.Second)
continue
}
time.Sleep(time.Minute)
start = GetStartDate()
} }
} }
@ -58,7 +64,7 @@ func GetStartDate() time.Time {
q := m.Select(qf.Max(m.Time)) q := m.Select(qf.Max(m.Time))
err := db.QueryRow(q).Scan(&t) err := db.QueryRow(q).Scan(&t)
if t == nil || err == sql.ErrNoRows { if t == nil || err == sql.ErrNoRows {
return time.Date(2018, 1, 1, 0, 0, 0, 0, time.Local) return time.Date(2018, 4, 1, 0, 0, 0, 0, time.Local)
} }
if err != nil { if err != nil {
panic(err) panic(err)