]> git.ipfire.org Git - ipfire.org.git/commitdiff
asterisk: Don't keep a permanent connection
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 Nov 2024 11:20:05 +0000 (11:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 27 Nov 2024 11:20:05 +0000 (11:20 +0000)
This was not very stable and caused that we sometimes could not render
the user pages.

Now, we establish a new connection with every request which is still
fast enough.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/asterisk.py

index f182776cf8fb1fd30bb9c52b59df69bfd6e49dab..10653dc573132676d39dfe3a1e9dc49e21fad325 100644 (file)
@@ -14,21 +14,6 @@ from .decorators import *
 logging.getLogger("panoramisk").setLevel(logging.INFO)
 
 class Asterisk(misc.Object):
-       def init(self):
-               self.__manager = None
-
-               loop = asyncio.get_event_loop()
-
-               # Connect as soon as the event loop starts
-               loop.create_task(self.connect())
-
-       @property
-       def manager(self):
-               if not self.__manager:
-                       raise RuntimeError("Asterisk is not connected")
-
-               return self.__manager
-
        async def connect(self):
                """
                        Connects to Asterisk
@@ -49,20 +34,17 @@ class Asterisk(misc.Object):
        def _on_connect(self, manager):
                logging.debug("Connection to Asterisk established")
 
-               # Close any existing connections
-               if self.__manager:
-                       self.__manager.close()
-
-               self.__manager = manager
-
        async def _fetch(self, cls, action, filter=None, data={}):
                objects = []
 
                # Collect arguments
                args = { "Action" : action } | data
 
+               # Connect to Asterisk
+               manager = await self.connect()
+
                # Run the action and parse all messages
-               for data in await self.manager.send_action(args):
+               for data in await manager.send_action(args):
                        if not "Event" in data or not data.Event == cls.event:
                                continue