]> git.aero2k.de Git - urlbot-v3.git/commitdiff
optimize connection usage
authorThorsten <mail@aero2k.de>
Sat, 24 Jun 2023 19:45:22 +0000 (21:45 +0200)
committerThorsten <mail@aero2k.de>
Sat, 24 Jun 2023 19:45:22 +0000 (21:45 +0200)
distbot/bot/worker.py

index 86bb9ead48c23d0873341446c971ed8140ddd8a5..70160b4acc00e5f95e4e53b702ea7ea3c2565a36 100644 (file)
@@ -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")