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 \
&& mkdir -p ${APP_LOGS_PATH}
ENV TINI_VERSION='0.15.0' \
TINI_SHA='4007655082f573603c02bc1d2137443c8e153af047ffd088d02ccc01e6f06170'
ENV TINI_VERSION='0.17.0'
# 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 \
&& chmod +x /bin/tini \
&& echo "$TINI_SHA /bin/tini" | sha256sum -c -
&& chmod +x /bin/tini
VOLUME ${APP_CONFIG_PATH}
VOLUME ${APP_LOGS_PATH}

View File

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

View File

@ -9,16 +9,16 @@ import (
)
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")
}
var client interface{}
// var client interface{}
var err error
if client, err = grpcPool.Get(); nil != err {
return "", err
}
defer grpcPool.Put(client)
// if client, err = grpcPool.Get(); nil != err {
// return "", err
// }
// defer grpcPool.Put(client)
sm := strings.Split(method, ".")
si := &ooas.ServerInput{
@ -27,7 +27,7 @@ func Exec(ctx context.Context, method string, params []string) (string, error) {
Params: params,
}
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
}

73
external/grpc/pool.go vendored
View File

@ -1,48 +1,61 @@
package grpc
import (
"google.golang.org/grpc"
cgp "git.loafle.net/commons_go/grpc_pool"
"git.loafle.net/commons_go/logging"
ooas "git.loafle.net/overflow/overflow_api_server/golang"
"git.loafle.net/overflow/overflow_server_app/config"
"google.golang.org/grpc"
)
var grpcPool cgp.Pool
var grpcClient ooas.OverflowApiServerClient
func ExternalInit() {
ph := &grpcPoolHandlers{}
ph.MaxCapacity = config.Config.GRPC.Pool.MaxCapacity
ph.MaxIdle = config.Config.GRPC.Pool.MaxIdle
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
conn, err := grpc.Dial(config.Config.GRPC.Addr, grpc.WithInsecure())
if nil != err {
logging.Logger().Panic(err)
}
grpcClient = ooas.NewOverflowApiServerClient(conn)
}
func ExternalDestroy() {
if nil != grpcPool {
grpcPool.Stop()
}
}
type grpcPoolHandlers struct {
cgp.PoolHandlers
}
// var grpcPool cgp.Pool
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)
// func ExternalInit() {
// ph := &grpcPoolHandlers{}
// ph.MaxCapacity = config.Config.GRPC.Pool.MaxCapacity
// ph.MaxIdle = config.Config.GRPC.Pool.MaxIdle
// ph.IdleTimeout = config.Config.GRPC.Pool.IdleTimeout
// ph.Wait = config.Config.GRPC.Pool.Wait
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
// }