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) log.Fatal(conn_err)
} }
return &RedisConnection{conn} c := &RedisConnection{conn}
go c.periodicKeepAlive()
return c
} }
type RedisConnection struct { type RedisConnection struct {
redis.Conn 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 { func (self *RedisConnection) GetHost(name string) *Host {
host := Host{Hostname: name} host := Host{Hostname: name}

View File

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