diff --git a/main.py b/main.py index 994c05d..7d8f0bb 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,6 @@ from tempfile import TemporaryDirectory +from typing import Optional, Any + import pika import threading import time @@ -42,6 +44,10 @@ NEW_DATA_RESPONSE = 1097 tasks = Queue() connected = set() +connection: Optional[pika.BlockingConnection] = None +channel: Optional[Any] = None +server: Optional[SimpleXMLRPCServer] = None + logger = logging.getLogger('xmlrpcserver') @@ -352,6 +358,8 @@ def pika_callback(ch, method, properties, body): def pika_task(): + global connection + global channel connection = pika.BlockingConnection(pika.URLParameters(Config.rabbit_conn)) channel = connection.channel() channel.basic_consume(queue=Config.rabbit_queue, on_message_callback=pika_callback) @@ -359,6 +367,7 @@ def pika_task(): channel.start_consuming() + def list_contents(dir_name): logger.warning('list_contents(%s)', dir_name) return os.listdir(dir_name) @@ -791,7 +800,8 @@ def bnd_disconnected(bnd_name: str): def xmlrpc_task(): - server = SimpleXMLRPCServer(('0.0.0.0', 9000), logRequests=False, allow_none=True) + global server + server = SimpleXMLRPCServer(('0.0.0.0', 9000), logRequests=True, allow_none=True) server.register_function(list_contents) server.register_function(aud_add) server.register_function(auth_response) @@ -889,6 +899,10 @@ async def correction_replication(bnd_name: str, schema: str): def main(): + global connection + global server + global channel + logger.setLevel(logging.INFO) logger.warning('Use Control-C to exit') @@ -909,6 +923,8 @@ def main(): uvicorn.run(app, host="0.0.0.0", port=8000) except KeyboardInterrupt: logger.warning('Exiting') + finally: + server.server_close() def vers_key(e):