From 460af90cfdfaf525da2b61dfef163de062068681 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sat, 24 Jun 2023 21:45:22 +0200 Subject: [PATCH] optimize connection usage --- distbot/bot/worker.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/distbot/bot/worker.py b/distbot/bot/worker.py index 86bb9ea..70160b4 100644 --- a/distbot/bot/worker.py +++ b/distbot/bot/worker.py @@ -55,6 +55,7 @@ class Worker(threading.Thread): def init_channel(self): self.connection = pika.BlockingConnection(pika.URLParameters(conf_get("amqp_uri"))) self.channel = self.connection.channel() + self.channel.exchange_declare(exchange='classifier', exchange_type='topic') def init_queue(self): @@ -110,11 +111,8 @@ class Worker(threading.Thread): self.connection.add_callback_threadsafe(callback=self.channel.stop_consuming) def run(self): - try: - self.register_plugin() - except: - logger.exception("Oops. Registration failed") self.init_channel() + self.register_plugin() self.init_queue() self.channel.basic_consume(queue=self.queue, on_message_callback=self.callback) @@ -124,11 +122,8 @@ class Worker(threading.Thread): raise NotImplementedError() def register_plugin(self): - - connection = pika.BlockingConnection(pika.URLParameters(conf_get("amqp_uri"))) - channel = connection.channel() - channel.queue_declare(queue='plugin_registry') - channel.basic_publish( + self.channel.queue_declare(queue='plugin_registry') + self.channel.basic_publish( exchange='', routing_key='plugin_registry', body=json.dumps(self.get_declaration()).encode("utf-8") -- 2.39.2