def dispatch_event(self, event_name: str, event_data: dict):
        """ Dispatch event """
        self.logger.debug("Dispatching event: %s, event data: %s", event_name, json.dumps(event_data))

        # Get the correlation ID if it exists, otherwise create one
        cid = locals.get_cid() or str(uuid4())
        event_data["cid"] = cid

        self.dispatch(event_name, event_data)
Esempio n. 2
0
    def call_service_method(self, service_name: str, method_name: str, use_async: bool, *args, **kwargs):
        """ Call an RPC method from a service """
        self.logger.debug("Calling service: %s, method: %s", service_name, method_name)

        try:
            # Get the correlation ID if it exists, otherwise create one
            cid = locals.get_cid() or str(uuid4())

            with self._get_connection_pool().next() as rpc:
                service = getattr(rpc, service_name)
                method = getattr(service, method_name)

                if use_async:
                    return method.call_async(cid, *args, **kwargs)
                else:
                    return method(cid, *args, **kwargs)

        except Exception as ex:
            self.logger.error("RPC call failed with error %s", getattr(ex, 'message', repr(ex)))
            raise ex
    def call_service_method(self, service_name: str, method_name: str, use_async: bool, *args, **kwargs):
        """ Call an RPC method from a service """
        self.logger.debug("Calling service: %s, method: %s", service_name, method_name)

        try:
            # Get the correlation ID if it exists, otherwise create one
            cid = locals.get_cid() or str(uuid4())

            with ClusterRpcProxy(self.config) as cluster_rpc:
                service = getattr(cluster_rpc, service_name)
                method = getattr(service, method_name)
                new_kwargs = {**kwargs, **{"cid": cid}}

                if use_async:
                    return method.call_async(*args, **new_kwargs)
                else:
                    return method(*args, **new_kwargs)

        except Exception as ex:
            self.logger.error("RPC call failed with error %s", getattr(ex, 'message', repr(ex)))
            raise ex
Esempio n. 4
0
 def _add_comment(self, sql):
     cid = get_cid()
     cid_sql_template = getattr(settings, "CID_SQL_COMMENT_TEMPLATE", "cid: {cid}")
     cid = cid.replace("/*", r"\/\*").replace("*/", r"\*\/")
     return "{}\n/* {} */".format(sql, cid_sql_template.format(cid=cid))
Esempio n. 5
0
File: log.py Progetto: sebdiem/cid
 def filter(self, record):
     record.cid = get_cid()
     return True
Esempio n. 6
0
 def filter(self, record):
     record.cid = get_cid()
     return True
Esempio n. 7
0
def correlation(logger, log_method, event_dict):
    """
    Adds the application correlation id to the logs.
    """
    event_dict['correlation'] = get_cid()
    return event_dict
Esempio n. 8
0
 def test_get_empty_cid(self):
     self.assertIsNone(get_cid())
Esempio n. 9
0
 def test_set_cid(self):
     self.assertIsNone(get_cid())
     set_cid(self.cid)
     self.assertEqual(self.cid, get_cid())
Esempio n. 10
0
 def _process_response(self, response):
     cid = get_cid()
     if cid and self.cid_response_header:
         response[self.cid_response_header] = cid
     return response
Esempio n. 11
0
 def _process_response(self, response):
     cid = get_cid()
     if cid and self.cid_response_header:
         response[self.cid_response_header] = cid
     return response
Esempio n. 12
0
 def test_set_cid(self):
     self.assertIsNone(get_cid())
     set_cid(self.cid)
     self.assertEqual(self.cid, get_cid())
Esempio n. 13
0
 def test_get_empty_cid(self):
     self.assertIsNone(get_cid())
Esempio n. 14
0
def make_json(path):
    jsondict = OrderedDict()
    jsondict["cid"] = get_cid()
    jsondict["path"] = path
    msg_q(TOPIC, jsondict)