Casper 4 долоо хоног өмнө
parent
commit
10e82e2ef3

+ 22 - 20
sri-server-bg02/lib/TopicListener.py

@@ -13,10 +13,14 @@ from lib.UserWorkRecord import UserWorkRecord
 
 topic_info_dict = {}  # {<topic_name>: <last_log_key>}
 
+
 def method_v001(_client, _userdata, message):
     """消息处理方法"""
+    # --- get ---
+    topic = _client.casper_info.get('topic')
+
     # --- debug ---
-    # methods.debug_log(f"TopicListener|17", f"#message.payload: {message.payload}")
+    # methods.debug_log(f"TopicListener|{topic}|23", f"#message.payload: {message.payload}")
     # return
 
     # --- check ---
@@ -32,15 +36,15 @@ def method_v001(_client, _userdata, message):
         vehicle_id = log_dict.get('VehicleID')
         cockpit_id = log_dict.get('cockpitID')
     except Exception as exception:
-        methods.debug_log("TopicListener|35", f"#message.payload: {message.payload}")
-        methods.debug_log("TopicListener|35", f"#exception: {exception.__class__.__name__}")
-        methods.debug_log("TopicListener|35", f"#traceback: {traceback.format_exc()}")
+        methods.debug_log(f"TopicListener|{topic}|39", f"#message.payload: {message.payload}")
+        methods.debug_log(f"TopicListener|{topic}|39", f"#exception: {exception.__class__.__name__}")
+        methods.debug_log(f"TopicListener|{topic}|39", f"#traceback: {traceback.format_exc()}")
         return
 
     # --- check ---
     log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
     if not log_uuid:
-        methods.debug_log(f"TopicListener|error50", f"user_uuid: {user_uuid}, log_time: {log_time}")
+        methods.debug_log(f"TopicListener|{topic}|39", f"user_uuid: {user_uuid}, log_time: {log_time}")
         return
 
     # --- fill log_list ---
@@ -97,7 +101,6 @@ def method_v001(_client, _userdata, message):
     ]
 
     # --- get ---
-    topic = _client.casper_info.get('topic')
     last_log_key = topic_info_dict.get(topic)
 
     # --- check ---
@@ -110,13 +113,11 @@ def method_v001(_client, _userdata, message):
     topic_info_dict[topic] = log_key
 
     # --- save ---
-    # methods.debug_log(f"TopicListener|113", f"#log_list: {log_list}")
+    # methods.debug_log(f"TopicListener|{topic}|116", f"#log_list: {log_list}")
     log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
 
-
-
 def method_c001(_client, _userdata, message):
     """消息处理方法"""
     """
@@ -171,19 +172,22 @@ def method_c001(_client, _userdata, message):
         'vehicleID': '0538'
     }
     """
+    # --- get ---
+    topic = _client.casper_info.get('topic')
+
     # --- debug ---
     # methods.debug_log(f"TopicListener|168", f"#_client: {_client.casper_info} | {type(_client.casper_info)}")
     # methods.debug_log(f"TopicListener|168", f"#_client: {_userdata} | {type(_userdata)}")
-    # methods.debug_log(f"TopicListener|168", f"#message.payload: {message.payload}")
+    # methods.debug_log(f"TopicListener|{topic}|179", f"#message.payload: {message.payload}")
     # return
 
     # --- check ---
     try:
         log_dict = json.loads(message.payload)
     except Exception as exception:
-        methods.debug_log("TopicListener|79", f"#message.payload: {message.payload}")
-        methods.debug_log("TopicListener|79", f"#exception: {exception.__class__.__name__}")
-        methods.debug_log("TopicListener|79", f"#traceback: {traceback.format_exc()}")
+        methods.debug_log(f"TopicListener|{topic}|186", f"#message.payload: {message.payload}")
+        methods.debug_log(f"TopicListener|{topic}|186", f"#exception: {exception.__class__.__name__}")
+        methods.debug_log(f"TopicListener|{topic}|186", f"#traceback: {traceback.format_exc()}")
         return
 
     # --- check ---
@@ -194,7 +198,7 @@ def method_c001(_client, _userdata, message):
     cockpit_id = log_dict.get('cockpitID')
     log_uuid = UserWorkRecord.get_log_uuid(user_uuid, log_time, vehicle_id, cockpit_id)
     if not log_uuid:
-        methods.debug_log(f"TopicListener|error92", f"user_uuid: {user_uuid}, log_time: {log_time}")
+        methods.debug_log(f"TopicListener|{topic}|201|error201", f"user_uuid: {user_uuid}, log_time: {log_time}")
         return
 
     # --- fill log_list ---
@@ -249,7 +253,6 @@ def method_c001(_client, _userdata, message):
     ]
 
     # --- get ---
-    topic = _client.casper_info.get('topic')
     last_log_key = topic_info_dict.get(topic)
 
     # --- check ---
@@ -262,7 +265,7 @@ def method_c001(_client, _userdata, message):
     topic_info_dict[topic] = log_key
 
     # --- save ---
-    # methods.debug_log(f"TopicListener|158", f"#log_list: {log_list}")
+    # methods.debug_log(f"TopicListener|{topic}|268", f"#log_list: {log_list}")
     log_file_path = os.path.join(Global.save_dir, f'{log_uuid}.log')
     methods.write_text(log_file_path, ' | '.join(log_list) + '\n', 'a')
 
@@ -271,17 +274,16 @@ class TopicListener:
     """
     """
 
-
     def __init__(self, subscribe_topic, method_name):
         self.subscribe_topic = subscribe_topic
         self.method_name = method_name
 
     def subscribe(self):
 
-
+        # --- define ---
         topic_info_dict[self.subscribe_topic] = str()
-        
 
+        # --- set ---
         if self.method_name == 'method_v001':
             method = method_v001
         elif self.method_name == 'method_c001':
@@ -289,7 +291,7 @@ class TopicListener:
         else:
             method = None
 
-
+        # --- start ---
         client = Global.emqx_factory.Client(host=Global.emqx_host, port=Global.emqx_port)
         client.casper_info = {
             'topic': self.subscribe_topic