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
1 changed files with 12 additions and 6 deletions

18
main.go
View File

@ -19,10 +19,9 @@ var db *qbdb.DB
func main() {
initDB()
startDate := GetStartDate()
for time.Now().After(startDate) {
start, end := startDate, startDate.AddDate(0, 0, 7)
start := GetStartDate()
for {
end := start.Add(time.Hour)
data := GetFortopData(start, end)
ranges := map[string][]Range{}
@ -46,7 +45,14 @@ func main() {
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))
err := db.QueryRow(q).Scan(&t)
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 {
panic(err)