Ejemplo n.º 1
0
 def on_exception(self, e: Exception, traceback_str: str):
     self.last_exception = e
     status = ResultAvro()
     status.code = ErrorCodes.ErrorInternalError.value
     status.message = ErrorCodes.ErrorInternalError.interpret(exception=e)
     status.details = traceback_str
     self.last_status = status
Ejemplo n.º 2
0
    def send_request(self, request: AbcMessageAvro) -> Tuple[ResultAvro, Any]:
        self.clear_last()

        status = ResultAvro()
        rret_val = None

        try:
            ret_val = self.producer.produce(topic=self.kafka_topic,
                                            record=request)

            self.logger.debug(
                Constants.MANAGEMENT_INTER_ACTOR_OUTBOUND_MESSAGE.format(
                    request.get_message_name(), self.kafka_topic))

            if ret_val:
                message_wrapper = self.message_processor.add_message(
                    message=request)

                with message_wrapper.condition:
                    message_wrapper.condition.wait(
                        Constants.MANAGEMENT_API_TIMEOUT_IN_SECONDS)

                if not message_wrapper.done:
                    self.logger.debug(
                        Constants.MANAGEMENT_API_TIMEOUT_OCCURRED)
                    self.message_processor.remove_message(
                        msg_id=request.get_message_id())
                    status.code = ErrorCodes.ErrorTransportTimeout.value
                    status.message = ErrorCodes.ErrorTransportTimeout.interpret(
                    )
                else:
                    self.logger.debug(
                        Constants.MANAGEMENT_INTER_ACTOR_INBOUND_MESSAGE.
                        format(message_wrapper.response))
                    status = message_wrapper.response.status
                    if status.code == 0:
                        rret_val = message_wrapper.response

            else:
                self.logger.debug(
                    Constants.MANAGEMENT_INTER_ACTOR_MESSAGE_FAILED.format(
                        request.get_message_name(), self.kafka_topic))
                status.code = ErrorCodes.ErrorTransportFailure.value
                status.message = ErrorCodes.ErrorTransportFailure.interpret()

        except Exception as e:
            self.last_exception = e
            status.code = ErrorCodes.ErrorInternalError.value
            status.message = ErrorCodes.ErrorInternalError.interpret(
                exception=e)
            status.details = traceback.format_exc()

        self.last_status = status

        return status, rret_val