Commits

Anonymous committed df1b351 Draft

use new websocket routing

Comments (0)

Files changed (1)

 import logging
+import gevent
 from araldo.util import dump_obj
 from plugins import PluginManager
 
     def __init__(self, sub_config):
         self._log = logging.getLogger("araldo")
         self._routes = sub_config
-        dump_obj(self._routes, self._log, "")
+        #dump_obj(self._routes, self._log, "")
         for source, destinations in self._routes.items():
             self._log.debug(
                 "Using route: %s --> %s",
                 source, ", ".join(destinations))
-        outbound_plugin_instances = PluginManager.plugin_instances()[
+        self._plugin_manager = PluginManager.get()
+        self._outbound = self._plugin_manager.plugin_instances()[
             "araldo.endpoints.outbound"]
-        self._outbound = dict((x.name(), x) for x in outbound_plugin_instances)
 
 
     def route(self, origin, message):
         """ Send message via all configured outgoing endpoints
         """
+        websockets = self._plugin_manager.plugin_instances()["araldo.endpoints.outbound"].get("websocket", {})
         route = self._routes.get(origin, None)
         if route is None:
             self._log.debug(
                 origin)
         else:
             for destination in route:
-                logging.debug(
+                self._log.debug(
                     "Routing %s --> %s", origin, destination)
+                if destination not in self._outbound:
+                    self._log.warning(
+                        "Destination '%s' not found; not routing",
+                        destination)
+                    continue
                 self._outbound[destination].send(message)
+
+                #websockets = websockets.copy()  # for iteration
+                #for websocket in websockets.values():
+                #    try:
+                #        websocket.send(str(message))
+                #        gevent.sleep(0)
+                #    except Exception as error:
+                #        del websockets[id(websocket)]