From 60b24a8aa7d6bc12629a64dded880fee99bc5439 Mon Sep 17 00:00:00 2001 From: creslinux Date: Sat, 23 Jun 2018 12:17:00 +0000 Subject: [PATCH] Added api server shutdown function, and exposed on HTTP as /stop_api url This will stop the running app gracefully - processing current api calls then shutting the werkzueg (run) listening server. Have also called this from the cleanup placeholder. I'm not sure this is what is intended by cleanup def. By which I mean there may be a thread left running with no app within - not sure how to check this just yet. tidied excessive logging. --- freqtrade/rpc/api_server.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/freqtrade/rpc/api_server.py b/freqtrade/rpc/api_server.py index d89bee5f9..40eb39943 100644 --- a/freqtrade/rpc/api_server.py +++ b/freqtrade/rpc/api_server.py @@ -1,3 +1,4 @@ +import json import threading import logging # import json @@ -13,7 +14,7 @@ logger = logging.getLogger(__name__) app = Flask(__name__) -class ApiServerSuperWrap(RPC): +class ApiServer(RPC): """ This class is for REST calls across api server """ @@ -78,14 +79,8 @@ class ApiServerSuperWrap(RPC): except Exception: logger.exception("Api server failed to start, exception message is:") - @property - def name(self) -> str: - # TODO: implement me - raise NotImplementedError - def send_msg(self, msg: str) -> None: - # TODO: implement me - raise NotImplementedError + pass def shutdown_api_server(self): """ @@ -111,14 +106,12 @@ class ApiServerSuperWrap(RPC): """ self.shutdown_api_server() # def cleanup(self) -> None: - # # TODO: implement me - # raise NotImplementedError + # pass """ Define the application methods here, called by app.add_url_rule each Telegram command should have a like local substitute """ - def stop_api(self): """ For calling shutdown_api_server over via api server HTTP""" self.shutdown_api_server() @@ -178,7 +171,7 @@ class ApiServerSuperWrap(RPC): Starts TradeThread in bot if stopped. """ msg = self._rpc_start() - return jsonify(msg) + return json.dumps(msg) def stop(self): """ @@ -187,4 +180,4 @@ class ApiServerSuperWrap(RPC): Stops TradeThread in bot if running """ msg = self._rpc_stop() - return jsonify(msg) + return json.dumps(msg)