-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll.go
59 lines (51 loc) · 1.35 KB
/
poll.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"log"
"strings"
"time"
"github.com/3cb/ssc"
"github.com/boltdb/bolt"
)
func poll(db *bolt.DB, pool *ssc.Pool) {
ticker := time.NewTicker(time.Minute * 5)
loc, _ := time.LoadLocation("America/Los_Angeles")
d := strings.Split(fmt.Sprint(time.Now().In(loc)), " ")[0]
f := []FireCall{}
t1, t2 := getDate()
f, err := updateFire(t1, t2)
if err != nil {
log.Printf("Unable to update fire calls: %v", err)
} else {
log.Printf("Fire updated")
}
buf := serialize(f, d)
err = updateDB(db, d, buf)
if err != nil {
log.Printf("Unable to save to database: %v\n", err)
}
pool.Inbound <- &ssc.Message{Type: 2, Payload: buf}
for {
<-ticker.C
d := strings.Split(fmt.Sprint(time.Now().In(loc)), " ")[0]
t1, t2 := getDate()
f, err = updateFire(t1, t2)
if err != nil {
log.Printf("Unable to update fire calls: %v", err)
} else {
log.Printf("Fire updated")
}
buf := serialize(f, d)
err = updateDB(db, d, buf)
if err != nil {
log.Printf("Unable to save to database: %v\n", err)
}
pool.Inbound <- &ssc.Message{Type: 2, Payload: buf}
}
}
func getDate() (string, string) {
loc, _ := time.LoadLocation("America/Los_Angeles")
t1 := strings.Split(fmt.Sprint(time.Now().In(loc)), " ")[0] + "T00:00:00"
t2 := strings.Split(fmt.Sprint(time.Now().In(loc).Add(time.Hour*24)), " ")[0] + "T00:00:00"
return t1, t2
}