Exemplo n.º 1
0
    def receiveMessage(self, message, sender):
        # outconnect = self.createActor(OutConnect, globalName = "OutConnect")
        # self.send(outconnect, message)
        #self.mTree_logger().log(24, "{!s} got {!s}".format(self, message))
        if not isinstance(message, ActorSystemMessage):
            try:
                if type(message) is dict:
                    logging.info("SHOULD BE SETTING UP LOGGER")
                    self.simulation_id = message["simulation_id"]
                    self.simulation_run_id = message["simulation_run_id"]
                    self.run_number = message["run_number"]
                    self.run_code = message["run_code"]
                    self.status = message["status"]
                    self.mes_directory = message["mes_directory"]
                    self.output_type = message["data_logging"]
                    self.simulation_configuration = message[
                        "simulation_configuration"]
                    self.setup_log_files_folder()
                    self.create_mes_status_file()

                elif type(message) is LogMessage:
                    if message.get_message_type() == "data":
                        if self.output_type == "json":
                            self.log_json_data(message)
                        else:
                            self.log_data(message)
                    elif message.get_message_type() == "log":
                        self.log_message(message)

                elif type(message) is SequenceEvent:
                    self.log_sequence_event(message)

                elif type(message) is Message:
                    if message.get_directive() == "update_mes_status":
                        self.update_mes_status(message.get_payload())

                # if "message_type" in message.keys():
                #     self.simulation_id = message["simulation_id"]
                #     self.mes_directory = message["mes_directory"]
                #     if "run_number" in message.keys():
                #         self.run_number = message["run_number"]
                # else:
                #     self.log_message(message)
            except Exception as e:
                logging.info("LOGGING CRASHED")
                logging.info(traceback.format_exc())
                logline = "MES CRASHING - EXCEPTION FOLLOWS - LOG ISSUE"
                log_message = LogMessage(message_type="log", content=logline)
                self.log_message(log_message)
                log_message = LogMessage(message_type="log",
                                         content=traceback.format_exc())
                self.log_message(log_message)
                self.actorSystemShutdown()

        elif isinstance(message, ActorExitRequest):
            # clean up logs before exit
            try:
                self.complete_log_files()
            except Exception as e:
                error_type, error, tb = sys.exc_info()
                error_message = "MES AGENT CRASHING - EXCEPTION FOLLOWS \n"
                error_message += "\tSource Message: " + str(message) + "\n"
                error_message += "\tError Type: " + str(error_type) + "\n"
                error_message += "\tError: " + str(error) + "\n"
                traces = traceback.extract_tb(tb)
                trace_output = "\tTrace Output: \n"

                for trace_line in traceback.format_list(traces):
                    trace_output += "\t" + trace_line + "\n"
                error_message += "\n"
                error_message += trace_output

                logging.info("LOGGING CRASHED DURING COMPLETION STAGE")
                logging.info(error_message)
Exemplo n.º 2
0
 def log_data(self, logline):
     log_message = LogMessage(message_type="data", content=logline)
     self.send(self.log_actor, log_message)