def actual_execution(self): Log.debug("Started Thread for executing the function") while True: try: msg = self.queue.get(True) if isinstance(msg, InternalQuitMessage): break Log.debug("Got a message from topic %s" % msg.topic) # deserialize message input_object = msg.serde.deserialize(msg.message.data()) # set current message in context self.contextimpl.set_current_message_context( msg.message.message_id(), msg.topic) output_object = None self.saved_log_handler = None if self.log_topic_handler is not None: self.saved_log_handler = log.remove_all_handlers() log.add_handler(self.log_topic_handler) successfully_executed = False try: # get user function start time for statistic calculation start_time = time.time() Stats.stat_last_invocation.labels( *self.metrics_labels).set(start_time * 1000.0) if self.function_class is not None: output_object = self.function_class.process( input_object, self.contextimpl) else: output_object = self.function_purefunction.process( input_object) successfully_executed = True Stats.stat_process_latency_ms.labels( *self.metrics_labels).observe( (time.time() - start_time) * 1000.0) Stats.stat_total_processed.labels( *self.metrics_labels).inc() except Exception as e: Log.exception("Exception while executing user method") Stats.stat_total_user_exceptions.labels( *self.metrics_labels).inc() self.stats.add_user_exception() if self.log_topic_handler is not None: log.remove_all_handlers() log.add_handler(self.saved_log_handler) if successfully_executed: self.process_result(output_object, msg) Stats.stat_total_processed_successfully.labels( *self.metrics_labels).inc() except Exception as e: Log.error("Uncaught exception in Python instance: %s" % e) Stats.stat_total_sys_exceptions.labels( *self.metrics_labels).inc() self.stats.add_sys_exception()
def actual_execution(self): Log.debug("Started Thread for executing the function") while True: try: msg = self.queue.get(True) if isinstance(msg, InternalQuitMessage): break Log.debug("Got a message from topic %s" % msg.topic) # deserialize message input_object = msg.serde.deserialize(msg.message.data()) # set current message in context self.contextimpl.set_current_message_context( msg.message, msg.topic) output_object = None self.saved_log_handler = None if self.log_topic_handler is not None: self.saved_log_handler = log.remove_all_handlers() log.add_handler(self.log_topic_handler) successfully_executed = False try: # get user function start time for statistic calculation self.stats.set_last_invocation(time.time()) # start timer for process time self.stats.process_time_start() if self.function_class is not None: output_object = self.function_class.process( input_object, self.contextimpl) else: output_object = self.function_purefunction.process( input_object) successfully_executed = True # stop timer for process time self.stats.process_time_end() except Exception as e: Log.exception("Exception while executing user method") self.stats.incr_total_user_exceptions(e) # If function throws exception then send neg ack for input message back to broker msg.consumer.negative_acknowledge(msg.message) if self.log_topic_handler is not None: log.remove_all_handlers() log.add_handler(self.saved_log_handler) if successfully_executed: self.process_result(output_object, msg) self.stats.incr_total_processed_successfully() except Exception as e: Log.error("Uncaught exception in Python instance: %s" % e) self.stats.incr_total_sys_exceptions(e) if msg: msg.consumer.negative_acknowledge(msg.message)
def actual_execution(self): Log.info("Started Thread for executing the function") while True: msg = self.queue.get(True) if isinstance(msg, InternalQuitMessage): break user_exception = False system_exception = False Log.debug("Got a message from topic %s" % msg.topic) input_object = None try: input_object = msg.serde.deserialize(msg.message.data()) except: self.current_stats.increment_deser_errors(msg.topic) self.total_stats.increment_deser_errors(msg.topic) continue self.contextimpl.set_current_message_context( msg.message.message_id(), msg.topic) output_object = None self.saved_log_handler = None try: if self.log_topic_handler is not None: self.saved_log_handler = log.remove_all_handlers() log.add_handler(self.log_topic_handler) start_time = time.time() self.current_stats.increment_processed(int(start_time) * 1000) self.total_stats.increment_processed(int(start_time) * 1000) if self.function_class is not None: output_object = self.function_class.process( input_object, self.contextimpl) else: output_object = self.function_purefunction.process( input_object) end_time = time.time() latency = (end_time - start_time) * 1000 self.total_stats.increment_successfully_processed(latency) self.current_stats.increment_successfully_processed(latency) self.process_result(output_object, msg) except Exception as e: if self.log_topic_handler is not None: log.remove_all_handlers() log.add_handler(self.saved_log_handler) Log.exception("Exception while executing user method") self.total_stats.record_user_exception(e) self.current_stats.record_user_exception(e) finally: if self.log_topic_handler is not None: log.remove_all_handlers() log.add_handler(self.saved_log_handler)
def actual_execution(self): Log.debug("Started Thread for executing the function") while True: msg = self.queue.get(True) if isinstance(msg, InternalQuitMessage): break user_exception = False system_exception = False Log.debug("Got a message from topic %s" % msg.topic) input_object = None try: input_object = msg.serde.deserialize(msg.message.data()) except: self.current_stats.increment_deser_errors(msg.topic) self.total_stats.increment_deser_errors(msg.topic) continue self.contextimpl.set_current_message_context(msg.message.message_id(), msg.topic) output_object = None self.saved_log_handler = None if self.log_topic_handler is not None: self.saved_log_handler = log.remove_all_handlers() log.add_handler(self.log_topic_handler) start_time = time.time() self.current_stats.increment_processed(int(start_time) * 1000) self.total_stats.increment_processed(int(start_time) * 1000) successfully_executed = False try: if self.function_class is not None: output_object = self.function_class.process(input_object, self.contextimpl) else: output_object = self.function_purefunction.process(input_object) successfully_executed = True except Exception as e: Log.exception("Exception while executing user method") self.total_stats.record_user_exception(e) self.current_stats.record_user_exception(e) end_time = time.time() latency = (end_time - start_time) * 1000 self.total_stats.increment_successfully_processed(latency) self.current_stats.increment_successfully_processed(latency) if self.log_topic_handler is not None: log.remove_all_handlers() log.add_handler(self.saved_log_handler) if successfully_executed: self.process_result(output_object, msg)