Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions cmd/hammer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"database/sql"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -34,6 +35,7 @@ import (
var (
logger *zap.Logger
sqlDB *sqlx.DB
sqlConn *sql.Conn
grpcEndpoint string
httpEndpoint string
)
Expand Down Expand Up @@ -118,16 +120,21 @@ func healthCheckServer() {
}
port := env.GetInt("HAMMER_HEALTH_CHECK_PORT", 9000)
mux := http.NewServeMux()
mux.HandleFunc("/liveness", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
mux.HandleFunc("/readiness", func(w http.ResponseWriter, r *http.Request) {
handler := func(w http.ResponseWriter, r *http.Request) {
if err := sqlDB.Ping(); err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if sqlConn != nil {
if err := sqlConn.PingContext(context.Background()); err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}
w.WriteHeader(http.StatusNoContent)
})
}
mux.HandleFunc("/liveness", handler)
mux.HandleFunc("/readiness", handler)
err := http.ListenAndServe(fmt.Sprintf(":%d", port), mux)
if err != nil {
logger.Error("health-check-server-failed-to-start", zap.Error(err))
Expand All @@ -147,6 +154,7 @@ func init() {
if err != nil {
logger.Fatal("failed-to-ping-database", zap.Error(err))
}
db.SetMaxOpenConns(env.GetInt("HAMMER_DATABASE_MAX_OPEN_CONNS", 3))
sqlDB = db

// Set grpc endpoint
Expand Down Expand Up @@ -269,10 +277,11 @@ func main() {
Usage: "Starts the worker",
Action: func(c *cli.Context) error {
// Create lock
sqlConn, err := sqlDB.DB.Conn(context.Background())
conn, err := sqlDB.DB.Conn(context.Background())
if err != nil {
return err
}
sqlConn = conn
lock := pglock.NewLock(sqlConn)

// Create worker service
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ require (
github.com/golang/protobuf v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.14.5
github.com/grpc-ecosystem/grpc-gateway v1.14.6
github.com/huandu/go-sqlbuilder v1.7.0
github.com/jmoiron/sqlx v1.2.0
github.com/joho/godotenv v1.3.0
github.com/lib/pq v1.5.2
github.com/lib/pq v1.7.0
github.com/oklog/ulid/v2 v2.0.2
github.com/prometheus/client_golang v1.6.0
github.com/stretchr/testify v1.5.1
github.com/prometheus/client_golang v1.7.1
github.com/stretchr/testify v1.6.1
github.com/urfave/cli/v2 v2.2.0
go.uber.org/zap v1.15.0
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2
google.golang.org/genproto v0.0.0-20200521103424-e9a78aa275b7
google.golang.org/grpc v1.29.1
google.golang.org/protobuf v1.23.0
golang.org/x/net v0.0.0-20200625001655-4c5254603344
google.golang.org/genproto v0.0.0-20200626011028-ee7919e894b5
google.golang.org/grpc v1.30.0
google.golang.org/protobuf v1.25.0
)
Loading