summaryrefslogtreecommitdiff
path: root/app/fetch.go
diff options
context:
space:
mode:
authorHorus32015-02-20 16:49:27 +0100
committerHorus32015-02-20 16:49:27 +0100
commitffe1b892b4c01c40215a1b8b5697fc35b81186b5 (patch)
treef4bf64faacb340e7587e638767abc11cff00524a /app/fetch.go
parent9fd1b6a54c77f78df1031a620fe3fb3887eda56d (diff)
downloadstatuspage-ffe1b892b4c01c40215a1b8b5697fc35b81186b5.tar.gz
Add caching struct as json in redis.
Diffstat (limited to 'app/fetch.go')
-rw-r--r--app/fetch.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/app/fetch.go b/app/fetch.go
index a03504e..82bbb7d 100644
--- a/app/fetch.go
+++ b/app/fetch.go
@@ -1,13 +1,15 @@
package main
import (
+ "encoding/json"
"fmt"
// "time"
+ "log"
)
func run() {
c := c
- c.AddFunc("@every 30s", healthCheck)
+ c.AddFunc("@every 10s", healthCheck)
c.Start()
jobs := c.Entries()
@@ -16,12 +18,31 @@ func run() {
}
}
+const (
+ cache_prefix = "status_"
+)
+
func healthCheck() {
h := []Host{}
db := Db
db.Find(&h)
- for _, v := range h {
+ c := pool.Get()
+ defer c.Close()
+
+ for k, v := range h {
+ // save struct in redis as serialized json
+ // TODO
+ j, err := json.Marshal(v)
+ if err != nil {
+ log.Println("Error: ", err)
+ continue
+ }
+
+ c.Do("SET", cache_prefix+string(k), j)
+
+ fmt.Println("Json: ", j)
+
fmt.Printf("Id: %v, Url: %v \n", v.Id, v.Url)
if resp, _, err := HttpGet(v.Url); err != nil {