Retrieve data every minute
This commit is contained in:
parent
2c4366ff1f
commit
bfee747b17
18
main.go
18
main.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user