mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 15:10:37 +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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user