mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 15:09:59 +00:00
grpc: add shutdown call for external management (#957)
* grpc: add shutdown call for external management * go mod: tidy * glorious: suggestion * Update engine/engine.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update engine/rpcserver.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update main.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update engine/rpcserver.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -5037,3 +5037,26 @@ func getCollateral(c *cli.Context) error {
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var shutdownCommand = &cli.Command{
|
||||
Name: "shutdown",
|
||||
Usage: "shuts down bot instance",
|
||||
Action: shutdown,
|
||||
}
|
||||
|
||||
func shutdown(c *cli.Context) error {
|
||||
conn, cancel, err := setupClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer closeConn(conn, cancel)
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderServiceClient(conn)
|
||||
result, err := client.Shutdown(c.Context, &gctrpc.ShutdownRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -202,6 +202,7 @@ func main() {
|
||||
currencyStateManagementCommand,
|
||||
getFuturesPositionsCommand,
|
||||
getCollateralCommand,
|
||||
shutdownCommand,
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
@@ -190,6 +190,7 @@ type GRPCConfig struct {
|
||||
ListenAddress string `json:"listenAddress"`
|
||||
GRPCProxyEnabled bool `json:"grpcProxyEnabled"`
|
||||
GRPCProxyListenAddress string `json:"grpcProxyListenAddress"`
|
||||
GRPCAllowBotShutdown bool `json:"grpcAllowBotShutdown"`
|
||||
TimeInNanoSeconds bool `json:"timeInNanoSeconds"`
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ type Engine struct {
|
||||
currencyStateManager *CurrencyStateManager
|
||||
Settings Settings
|
||||
uptime time.Time
|
||||
GRPCShutdownSignal chan struct{}
|
||||
ServicesWG sync.WaitGroup
|
||||
}
|
||||
|
||||
@@ -181,6 +182,13 @@ func validateSettings(b *Engine, s *Settings, flagSet FlagSet) {
|
||||
|
||||
flagSet.WithBool("grpc", &b.Settings.EnableGRPC, b.Config.RemoteControl.GRPC.Enabled)
|
||||
flagSet.WithBool("grpcproxy", &b.Settings.EnableGRPCProxy, b.Config.RemoteControl.GRPC.GRPCProxyEnabled)
|
||||
|
||||
flagSet.WithBool("grpcshutdown", &b.Settings.EnableGRPCShutdown, b.Config.RemoteControl.GRPC.GRPCAllowBotShutdown)
|
||||
if b.Settings.EnableGRPCShutdown {
|
||||
b.GRPCShutdownSignal = make(chan struct{})
|
||||
go b.waitForGPRCShutdown()
|
||||
}
|
||||
|
||||
flagSet.WithBool("websocketrpc", &b.Settings.EnableWebsocketRPC, b.Config.RemoteControl.WebsocketRPC.Enabled)
|
||||
flagSet.WithBool("deprecatedrpc", &b.Settings.EnableDeprecatedRPC, b.Config.RemoteControl.DeprecatedRPC.Enabled)
|
||||
|
||||
@@ -260,6 +268,7 @@ func PrintSettings(s *Settings) {
|
||||
gctlog.Debugf(gctlog.Global, "\t Portfolio manager sleep delay: %v\n", s.PortfolioManagerDelay)
|
||||
gctlog.Debugf(gctlog.Global, "\t Enable gPRC: %v", s.EnableGRPC)
|
||||
gctlog.Debugf(gctlog.Global, "\t Enable gRPC Proxy: %v", s.EnableGRPCProxy)
|
||||
gctlog.Debugf(gctlog.Global, "\t Enable gRPC shutdown of bot instance: %v", s.EnableGRPCShutdown)
|
||||
gctlog.Debugf(gctlog.Global, "\t Enable websocket RPC: %v", s.EnableWebsocketRPC)
|
||||
gctlog.Debugf(gctlog.Global, "\t Enable deprecated RPC: %v", s.EnableDeprecatedRPC)
|
||||
gctlog.Debugf(gctlog.Global, "\t Enable comms relayer: %v", s.EnableCommsRelayer)
|
||||
@@ -968,3 +977,11 @@ func (bot *Engine) SetDefaultWebsocketDataHandler() error {
|
||||
}
|
||||
return bot.websocketRoutineManager.setWebsocketDataHandler(bot.websocketRoutineManager.websocketDataHandler)
|
||||
}
|
||||
|
||||
// waitForGPRCShutdown routines waits for a signal from the grpc server to
|
||||
// send a shutdown signal.
|
||||
func (bot *Engine) waitForGPRCShutdown() {
|
||||
<-bot.GRPCShutdownSignal
|
||||
gctlog.Warnln(gctlog.Global, "Captured gRPC shutdown request.")
|
||||
bot.Settings.Shutdown <- struct{}{}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ type Settings struct {
|
||||
PortfolioManagerDelay time.Duration
|
||||
EnableGRPC bool
|
||||
EnableGRPCProxy bool
|
||||
EnableGRPCShutdown bool
|
||||
EnableWebsocketRPC bool
|
||||
EnableDeprecatedRPC bool
|
||||
EnableCommsRelayer bool
|
||||
@@ -90,6 +91,9 @@ type Settings struct {
|
||||
|
||||
// Withdraw settings
|
||||
WithdrawCacheSize uint64
|
||||
|
||||
// Main shutdown channel
|
||||
Shutdown chan struct{}
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -53,22 +53,24 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errExchangeNotLoaded = errors.New("exchange is not loaded/doesn't exist")
|
||||
errExchangeNotEnabled = errors.New("exchange is not enabled")
|
||||
errExchangeBaseNotFound = errors.New("cannot get exchange base")
|
||||
errInvalidArguments = errors.New("invalid arguments received")
|
||||
errExchangeNameUnset = errors.New("exchange name unset")
|
||||
errCurrencyPairUnset = errors.New("currency pair unset")
|
||||
errInvalidTimes = errors.New("invalid start and end times")
|
||||
errAssetTypeDisabled = errors.New("asset type is disabled")
|
||||
errAssetTypeUnset = errors.New("asset type unset")
|
||||
errDispatchSystem = errors.New("dispatch system offline")
|
||||
errCurrencyNotEnabled = errors.New("currency not enabled")
|
||||
errCurrencyNotSpecified = errors.New("a currency must be specified")
|
||||
errCurrencyPairInvalid = errors.New("currency provided is not found in the available pairs list")
|
||||
errNoTrades = errors.New("no trades returned from supplied params")
|
||||
errNilRequestData = errors.New("nil request data received, cannot continue")
|
||||
errNoAccountInformation = errors.New("account information does not exist")
|
||||
errExchangeNotLoaded = errors.New("exchange is not loaded/doesn't exist")
|
||||
errExchangeNotEnabled = errors.New("exchange is not enabled")
|
||||
errExchangeBaseNotFound = errors.New("cannot get exchange base")
|
||||
errInvalidArguments = errors.New("invalid arguments received")
|
||||
errExchangeNameUnset = errors.New("exchange name unset")
|
||||
errCurrencyPairUnset = errors.New("currency pair unset")
|
||||
errInvalidTimes = errors.New("invalid start and end times")
|
||||
errAssetTypeDisabled = errors.New("asset type is disabled")
|
||||
errAssetTypeUnset = errors.New("asset type unset")
|
||||
errDispatchSystem = errors.New("dispatch system offline")
|
||||
errCurrencyNotEnabled = errors.New("currency not enabled")
|
||||
errCurrencyNotSpecified = errors.New("a currency must be specified")
|
||||
errCurrencyPairInvalid = errors.New("currency provided is not found in the available pairs list")
|
||||
errNoTrades = errors.New("no trades returned from supplied params")
|
||||
errNilRequestData = errors.New("nil request data received, cannot continue")
|
||||
errNoAccountInformation = errors.New("account information does not exist")
|
||||
errShutdownNotAllowed = errors.New("shutting down this bot instance is not allowed via gRPC, please enable by command line flag --grpcshutdown or config.json field grpcAllowBotShutdown")
|
||||
errGRPCShutdownSignalIsNil = errors.New("cannot shutdown, gRPC shutdown channel is nil")
|
||||
)
|
||||
|
||||
// RPCServer struct
|
||||
@@ -4561,3 +4563,18 @@ func (s *RPCServer) GetCollateral(ctx context.Context, r *gctrpc.GetCollateralRe
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Shutdown terminates bot session externally
|
||||
func (s *RPCServer) Shutdown(_ context.Context, _ *gctrpc.ShutdownRequest) (*gctrpc.ShutdownResponse, error) {
|
||||
if !s.Engine.Settings.EnableGRPCShutdown {
|
||||
return nil, errShutdownNotAllowed
|
||||
}
|
||||
|
||||
if s.Engine.GRPCShutdownSignal == nil {
|
||||
return nil, errGRPCShutdownSignalIsNil
|
||||
}
|
||||
|
||||
s.Engine.GRPCShutdownSignal <- struct{}{}
|
||||
s.Engine.GRPCShutdownSignal = nil
|
||||
return &gctrpc.ShutdownResponse{}, nil
|
||||
}
|
||||
|
||||
@@ -2304,3 +2304,24 @@ func TestGetCollateral(t *testing.T) {
|
||||
t.Errorf("received '%v', expected '%v'", err, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShutdown(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := RPCServer{Engine: &Engine{}}
|
||||
_, err := s.Shutdown(context.Background(), &gctrpc.ShutdownRequest{})
|
||||
if !errors.Is(err, errShutdownNotAllowed) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, errShutdownNotAllowed)
|
||||
}
|
||||
|
||||
s.Engine.Settings.EnableGRPCShutdown = true
|
||||
_, err = s.Shutdown(context.Background(), &gctrpc.ShutdownRequest{})
|
||||
if !errors.Is(err, errGRPCShutdownSignalIsNil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, errGRPCShutdownSignalIsNil)
|
||||
}
|
||||
|
||||
s.Engine.GRPCShutdownSignal = make(chan struct{}, 1)
|
||||
_, err = s.Shutdown(context.Background(), &gctrpc.ShutdownRequest{})
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
}
|
||||
|
||||
1782
gctrpc/rpc.pb.go
1782
gctrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@@ -3095,6 +3095,24 @@ func local_request_GoCryptoTraderService_GetCollateral_0(ctx context.Context, ma
|
||||
|
||||
}
|
||||
|
||||
func request_GoCryptoTraderService_Shutdown_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ShutdownRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.Shutdown(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_GoCryptoTraderService_Shutdown_0(ctx context.Context, marshaler runtime.Marshaler, server GoCryptoTraderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ShutdownRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.Shutdown(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterGoCryptoTraderServiceHandlerServer registers the http handlers for service GoCryptoTraderService to "mux".
|
||||
// UnaryRPC :call GoCryptoTraderServiceServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
@@ -5303,6 +5321,30 @@ func RegisterGoCryptoTraderServiceHandlerServer(ctx context.Context, mux *runtim
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTraderService_Shutdown_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/gctrpc.GoCryptoTraderService/Shutdown", runtime.WithHTTPPathPattern("/v1/shutdown"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_GoCryptoTraderService_Shutdown_0(ctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTraderService_Shutdown_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7360,6 +7402,27 @@ func RegisterGoCryptoTraderServiceHandlerClient(ctx context.Context, mux *runtim
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTraderService_Shutdown_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
ctx, err = runtime.AnnotateContext(ctx, mux, req, "/gctrpc.GoCryptoTraderService/Shutdown", runtime.WithHTTPPathPattern("/v1/shutdown"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_GoCryptoTraderService_Shutdown_0(ctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTraderService_Shutdown_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7555,6 +7618,8 @@ var (
|
||||
pattern_GoCryptoTraderService_GetFuturesPositions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getfuturespositions"}, ""))
|
||||
|
||||
pattern_GoCryptoTraderService_GetCollateral_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcollateral"}, ""))
|
||||
|
||||
pattern_GoCryptoTraderService_Shutdown_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "shutdown"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -7749,4 +7814,6 @@ var (
|
||||
forward_GoCryptoTraderService_GetFuturesPositions_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_GoCryptoTraderService_GetCollateral_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_GoCryptoTraderService_Shutdown_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
|
||||
@@ -1115,6 +1115,10 @@ message CollateralUsedBreakdown {
|
||||
string used_in_spot_margin = 8;
|
||||
}
|
||||
|
||||
message ShutdownRequest {}
|
||||
|
||||
message ShutdownResponse {}
|
||||
|
||||
service GoCryptoTraderService {
|
||||
rpc GetInfo(GetInfoRequest) returns (GetInfoResponse) {
|
||||
option (google.api.http) = {
|
||||
@@ -1713,4 +1717,9 @@ service GoCryptoTraderService {
|
||||
get: "/v1/getcollateral"
|
||||
};
|
||||
}
|
||||
rpc Shutdown(ShutdownRequest) returns (ShutdownResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/shutdown"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3042,6 +3042,28 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/shutdown": {
|
||||
"get": {
|
||||
"operationId": "GoCryptoTraderService_Shutdown",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/gctrpcShutdownResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"GoCryptoTraderService"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/simulateorder": {
|
||||
"post": {
|
||||
"operationId": "GoCryptoTraderService_SimulateOrder",
|
||||
@@ -5346,6 +5368,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"gctrpcShutdownResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
"gctrpcSimulateOrderRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -118,6 +118,7 @@ type GoCryptoTraderServiceClient interface {
|
||||
CurrencyStateTradingPair(ctx context.Context, in *CurrencyStateTradingPairRequest, opts ...grpc.CallOption) (*GenericResponse, error)
|
||||
GetFuturesPositions(ctx context.Context, in *GetFuturesPositionsRequest, opts ...grpc.CallOption) (*GetFuturesPositionsResponse, error)
|
||||
GetCollateral(ctx context.Context, in *GetCollateralRequest, opts ...grpc.CallOption) (*GetCollateralResponse, error)
|
||||
Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error)
|
||||
}
|
||||
|
||||
type goCryptoTraderServiceClient struct {
|
||||
@@ -1130,6 +1131,15 @@ func (c *goCryptoTraderServiceClient) GetCollateral(ctx context.Context, in *Get
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *goCryptoTraderServiceClient) Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error) {
|
||||
out := new(ShutdownResponse)
|
||||
err := c.cc.Invoke(ctx, "/gctrpc.GoCryptoTraderService/Shutdown", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GoCryptoTraderServiceServer is the server API for GoCryptoTraderService service.
|
||||
// All implementations must embed UnimplementedGoCryptoTraderServiceServer
|
||||
// for forward compatibility
|
||||
@@ -1230,6 +1240,7 @@ type GoCryptoTraderServiceServer interface {
|
||||
CurrencyStateTradingPair(context.Context, *CurrencyStateTradingPairRequest) (*GenericResponse, error)
|
||||
GetFuturesPositions(context.Context, *GetFuturesPositionsRequest) (*GetFuturesPositionsResponse, error)
|
||||
GetCollateral(context.Context, *GetCollateralRequest) (*GetCollateralResponse, error)
|
||||
Shutdown(context.Context, *ShutdownRequest) (*ShutdownResponse, error)
|
||||
mustEmbedUnimplementedGoCryptoTraderServiceServer()
|
||||
}
|
||||
|
||||
@@ -1525,6 +1536,9 @@ func (UnimplementedGoCryptoTraderServiceServer) GetFuturesPositions(context.Cont
|
||||
func (UnimplementedGoCryptoTraderServiceServer) GetCollateral(context.Context, *GetCollateralRequest) (*GetCollateralResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetCollateral not implemented")
|
||||
}
|
||||
func (UnimplementedGoCryptoTraderServiceServer) Shutdown(context.Context, *ShutdownRequest) (*ShutdownResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Shutdown not implemented")
|
||||
}
|
||||
func (UnimplementedGoCryptoTraderServiceServer) mustEmbedUnimplementedGoCryptoTraderServiceServer() {}
|
||||
|
||||
// UnsafeGoCryptoTraderServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
@@ -3284,6 +3298,24 @@ func _GoCryptoTraderService_GetCollateral_Handler(srv interface{}, ctx context.C
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _GoCryptoTraderService_Shutdown_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ShutdownRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(GoCryptoTraderServiceServer).Shutdown(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/gctrpc.GoCryptoTraderService/Shutdown",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(GoCryptoTraderServiceServer).Shutdown(ctx, req.(*ShutdownRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// GoCryptoTraderService_ServiceDesc is the grpc.ServiceDesc for GoCryptoTraderService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@@ -3651,6 +3683,10 @@ var GoCryptoTraderService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "GetCollateral",
|
||||
Handler: _GoCryptoTraderService_GetCollateral_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Shutdown",
|
||||
Handler: _GoCryptoTraderService_Shutdown_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
|
||||
12
main.go
12
main.go
@@ -39,6 +39,7 @@ func main() {
|
||||
flag.DurationVar(&settings.PortfolioManagerDelay, "portfoliomanagerdelay", time.Duration(0), "sets the portfolio managers sleep delay between updates")
|
||||
flag.BoolVar(&settings.EnableGRPC, "grpc", true, "enables the grpc server")
|
||||
flag.BoolVar(&settings.EnableGRPCProxy, "grpcproxy", false, "enables the grpc proxy server")
|
||||
flag.BoolVar(&settings.EnableGRPCShutdown, "grpcshutdown", false, "enables gRPC bot instance shutdown functionality")
|
||||
flag.BoolVar(&settings.EnableWebsocketRPC, "websocketrpc", true, "enables the websocket RPC server")
|
||||
flag.BoolVar(&settings.EnableDeprecatedRPC, "deprecatedrpc", true, "enables the deprecated RPC server")
|
||||
flag.BoolVar(&settings.EnableCommsRelayer, "enablecommsrelayer", true, "enables available communications relayer")
|
||||
@@ -127,6 +128,7 @@ func main() {
|
||||
settings.ConfigFile = ""
|
||||
}
|
||||
|
||||
settings.Shutdown = make(chan struct{})
|
||||
engine.Bot, err = engine.NewFromSettings(&settings, flagSet)
|
||||
if engine.Bot == nil || err != nil {
|
||||
log.Fatalf("Unable to initialise bot engine. Error: %s\n", err)
|
||||
@@ -141,8 +143,14 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
interrupt := signaler.WaitForInterrupt()
|
||||
gctlog.Infof(gctlog.Global, "Captured %v, shutdown requested.\n", interrupt)
|
||||
go waitForInterupt(settings.Shutdown)
|
||||
<-settings.Shutdown
|
||||
engine.Bot.Stop()
|
||||
gctlog.Infoln(gctlog.Global, "Exiting.")
|
||||
}
|
||||
|
||||
func waitForInterupt(waiter chan<- struct{}) {
|
||||
interrupt := signaler.WaitForInterrupt()
|
||||
gctlog.Infof(gctlog.Global, "Captured %v, shutdown requested.\n", interrupt)
|
||||
waiter <- struct{}{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user