This commit is contained in:
crusader 2018-03-26 23:47:55 +09:00
parent 25bb9aca92
commit 24f1d2c389
4 changed files with 53 additions and 42 deletions

View File

@ -15,13 +15,11 @@ RUN apk add --no-cache curl \
&& chmod +x ${APP_HOME}/bin/*.sh \ && chmod +x ${APP_HOME}/bin/*.sh \
&& mkdir -p ${APP_LOGS_PATH} && mkdir -p ${APP_LOGS_PATH}
ENV TINI_VERSION='0.15.0' \ ENV TINI_VERSION='0.17.0'
TINI_SHA='4007655082f573603c02bc1d2137443c8e153af047ffd088d02ccc01e6f06170'
# Use tini as subreaper in Docker container to adopt zombie processes # Use tini as subreaper in Docker container to adopt zombie processes
RUN curl -fsSL https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-amd64 -o /bin/tini \ RUN curl -fsSL https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-static-amd64 -o /bin/tini \
&& chmod +x /bin/tini \ && chmod +x /bin/tini
&& echo "$TINI_SHA /bin/tini" | sha256sum -c -
VOLUME ${APP_CONFIG_PATH} VOLUME ${APP_CONFIG_PATH}
VOLUME ${APP_LOGS_PATH} VOLUME ${APP_LOGS_PATH}

View File

@ -11,7 +11,7 @@
"signingKey": "tWB0lUXiCwX4U3qsJZcZ10mKvEH793RHkTJDbDuZVshQTk4uNB6ck59UQ96lhsRi4XNUiEnlIbP8XYQMPabeNtERX3iyHeDcwocgUVAor1nkAajYeq1gNyJszGpMhEOT" "signingKey": "tWB0lUXiCwX4U3qsJZcZ10mKvEH793RHkTJDbDuZVshQTk4uNB6ck59UQ96lhsRi4XNUiEnlIbP8XYQMPabeNtERX3iyHeDcwocgUVAor1nkAajYeq1gNyJszGpMhEOT"
}, },
"gRPC": { "gRPC": {
"addr": "127.0.0.1:50006", "addr": "192.168.1.50:50006",
"tls": false, "tls": false,
"pool": { "pool": {
"maxIdle": 1, "maxIdle": 1,

View File

@ -9,16 +9,16 @@ import (
) )
func Exec(ctx context.Context, method string, params []string) (string, error) { func Exec(ctx context.Context, method string, params []string) (string, error) {
if nil == grpcPool { if nil == grpcClient {
return "", fmt.Errorf("App: GRPC Pool is not initialized") return "", fmt.Errorf("App: GRPC Pool is not initialized")
} }
var client interface{} // var client interface{}
var err error var err error
if client, err = grpcPool.Get(); nil != err { // if client, err = grpcPool.Get(); nil != err {
return "", err // return "", err
} // }
defer grpcPool.Put(client) // defer grpcPool.Put(client)
sm := strings.Split(method, ".") sm := strings.Split(method, ".")
si := &ooas.ServerInput{ si := &ooas.ServerInput{
@ -27,7 +27,7 @@ func Exec(ctx context.Context, method string, params []string) (string, error) {
Params: params, Params: params,
} }
var so *ooas.ServerOutput var so *ooas.ServerOutput
if so, err = client.(ooas.OverflowApiServerClient).Exec(ctx, si); nil != err { if so, err = grpcClient.(ooas.OverflowApiServerClient).Exec(ctx, si); nil != err {
return "", err return "", err
} }

73
external/grpc/pool.go vendored
View File

@ -1,48 +1,61 @@
package grpc package grpc
import ( import (
"google.golang.org/grpc"
cgp "git.loafle.net/commons_go/grpc_pool"
"git.loafle.net/commons_go/logging" "git.loafle.net/commons_go/logging"
ooas "git.loafle.net/overflow/overflow_api_server/golang" ooas "git.loafle.net/overflow/overflow_api_server/golang"
"git.loafle.net/overflow/overflow_server_app/config" "git.loafle.net/overflow/overflow_server_app/config"
"google.golang.org/grpc"
) )
var grpcPool cgp.Pool var grpcClient ooas.OverflowApiServerClient
func ExternalInit() { func ExternalInit() {
ph := &grpcPoolHandlers{} conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure())
ph.MaxCapacity = config.Config.GRPC.Pool.MaxCapacity if nil != err {
ph.MaxIdle = config.Config.GRPC.Pool.MaxIdle logging.Logger().Panic(err)
ph.IdleTimeout = config.Config.GRPC.Pool.IdleTimeout
ph.Wait = config.Config.GRPC.Pool.Wait
grpcPool = cgp.New(ph)
if err := grpcPool.Start(); nil != err {
logging.Logger().Panicf("App: %v", err)
return
} }
grpcClient = ooas.NewOverflowApiServerClient(conn)
} }
func ExternalDestroy() { func ExternalDestroy() {
if nil != grpcPool {
grpcPool.Stop()
}
} }
type grpcPoolHandlers struct { // var grpcPool cgp.Pool
cgp.PoolHandlers
}
func (h *grpcPoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) { // func ExternalInit() {
var err error // ph := &grpcPoolHandlers{}
conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure()) // ph.MaxCapacity = config.Config.GRPC.Pool.MaxCapacity
if nil != err { // ph.MaxIdle = config.Config.GRPC.Pool.MaxIdle
return nil, nil, err // ph.IdleTimeout = config.Config.GRPC.Pool.IdleTimeout
} // ph.Wait = config.Config.GRPC.Pool.Wait
c := ooas.NewOverflowApiServerClient(conn)
return conn, c, nil // grpcPool = cgp.New(ph)
}
// if err := grpcPool.Start(); nil != err {
// logging.Logger().Panicf("App: %v", err)
// return
// }
// }
// func ExternalDestroy() {
// if nil != grpcPool {
// grpcPool.Stop()
// }
// }
// type grpcPoolHandlers struct {
// cgp.PoolHandlers
// }
// func (h *grpcPoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) {
// var err error
// conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure())
// if nil != err {
// return nil, nil, err
// }
// c := ooas.NewOverflowApiServerClient(conn)
// return conn, c, nil
// }