Added health check for redis connection
This commit is contained in:
parent
6d72f5aaaa
commit
947a556871
|
@ -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}
|
||||||
|
|
||||||
|
|
24
ddns.go
24
ddns.go
|
@ -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,19 +63,19 @@ func RunWebService() {
|
||||||
conn := connection.OpenConnection()
|
conn := connection.OpenConnection()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
// 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 := gin.Default()
|
||||||
|
r.HTMLTemplates = html
|
||||||
|
|
||||||
// Add index template from bindata
|
r.GET("/", func(g *gin.Context) {
|
||||||
index_content, err := Asset("templates/index.html")
|
g.HTML(200, "index.html", nil)
|
||||||
HandleErr(err)
|
})
|
||||||
|
|
||||||
html, err := template.New("index.html").Parse(string(index_content))
|
|
||||||
HandleErr(err)
|
|
||||||
r.HTMLTemplates = html
|
|
||||||
|
|
||||||
r.GET("/", func (g *gin.Context) {
|
|
||||||
g.HTML(200, "index.html", nil)
|
|
||||||
})
|
|
||||||
|
|
||||||
r.GET("/new/:hostname", func(c *gin.Context) {
|
r.GET("/new/:hostname", func(c *gin.Context) {
|
||||||
hostname := c.Params.ByName("hostname")
|
hostname := c.Params.ByName("hostname")
|
||||||
|
|
Loading…
Reference in New Issue