From: Thorsten Date: Sat, 24 Jun 2023 19:45:22 +0000 (+0200) Subject: optimize connection usage X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=460af90cfdfaf525da2b61dfef163de062068681;p=urlbot-v3.git optimize connection usage --- 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")