Example #1
0
    def conn(self, name, metadata, throw=False):
        c = self.conns.get(name, None)
        if not c:
            url = self.metas.get(name, None)
            if not url:
                if not throw:
                    return None
                raise exceptions.ConnectionNotFoundError(
                    message='Connection {} not found'.format(name),
                    metadata=metadata)
            this_conn = Connection(name=name,
                                   uri=url,
                                   max_retry=settings.MAX_RETRY)
            threaded = {threading.get_ident(): this_conn}
            self.conns[name] = threaded
            return this_conn

        tid = threading.get_ident()
        rconn = c.get(tid, None)
        if not rconn:
            url = self.metas.get(name, None)
            if not url:
                if not throw:
                    return None
                raise exceptions.ConnectionNotFoundError(
                    'Connection {} not found'.format(name), metadata=metadata)
            this_conn = Connection(name=name,
                                   uri=url,
                                   max_retry=settings.MAX_RETRY)
            c[tid] = this_conn
            return this_conn

        return rconn
Example #2
0
    def query_conn(self, name, metadata=None):
        if not name:
            raise exceptions.ConnectionNotFoundError(
                message=
                f'Conn Group is Empty. Please Check your configurations',
                metadata=metadata)

        group = self.readonly_topo.get_group(name)
        if not group:
            raise exceptions.ConnectionNotFoundError(
                message=
                f'Conn Group {name} is Empty. Please Check your configurations',
                metadata=metadata)
        conn = group.get(name).fetch()
        if not conn:
            raise exceptions.ConnectionNotFoundError(
                message=f'Conn {name} Not Found', metadata=metadata)
        conn.on_connect(metadata=metadata)
        return conn
Example #3
0
 def query_conn(self, name, metadata=None):
     conn = self.readonly_topo.get_group(name).get(name).fetch()
     if not conn:
         raise exceptions.ConnectionNotFoundError(name, metadata=metadata)
     conn.on_connect(metadata=metadata)
     return conn.conn
Example #4
0
 def query_conn(self, name, metadata=None):
     conn = self.conn_mgr.conn(name, metadata=metadata)
     if not conn:
         raise exceptions.ConnectionNotFoundError(name, metadata=metadata)
     conn.on_connect(metadata=metadata)
     return conn.conn