Added health check for redis connection

This commit is contained in:
Philipp Böhm 2014-07-15 18:21:11 +02:00
parent 6d72f5aaaa
commit 947a556871
2 changed files with 26 additions and 13 deletions

View File

@ -23,13 +23,26 @@ func OpenConnection() *RedisConnection {
log.Fatal(conn_err)
}
return &RedisConnection{conn}
c := &RedisConnection{conn}
go c.periodicKeepAlive()
return c
}
type RedisConnection struct {
redis.Conn
}
// Every minute send a Ping signal to redis so that we dont run into a timeout
func (self *RedisConnection) periodicKeepAlive() {
c := time.Tick(1 * time.Minute)
for _ = range c {
_, err := self.Do("PING")
HandleErr(err)
}
}
func (self *RedisConnection) GetHost(name string) *Host {
host := Host{Hostname: name}

View File

@ -5,10 +5,10 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/pboehm/ddns/connection"
"html/template"
"log"
"net"
"net/http"
"html/template"
"os"
"strings"
)
@ -63,17 +63,17 @@ func RunWebService() {
conn := connection.OpenConnection()
defer conn.Close()
r := gin.Default()
// Add index template from bindata
index_content, err := Asset("templates/index.html")
HandleErr(err)
html, err := template.New("index.html").Parse(string(index_content))
HandleErr(err)
r := gin.Default()
r.HTMLTemplates = html
r.GET("/", func (g *gin.Context) {
r.GET("/", func(g *gin.Context) {
g.HTML(200, "index.html", nil)
})