casper hace 1 mes
padre
commit
ada7633f63
Se han modificado 1 ficheros con 20 adiciones y 17 borrados
  1. 20 17
      sri-server-bg02/lib/JobManage.py

+ 20 - 17
sri-server-bg02/lib/JobManage.py

@@ -6,7 +6,7 @@ import os
 # save_dir = f'/home/server/logs'
 # save_dir = f'/home/server/logs'
 
 
 # --- for windows
 # --- for windows
-save_dir = r'C:\temp'  # sri内网测试环境
+save_dir = r'C:\logs'  # sri内网测试环境
 
 
 class JobManage(object):
 class JobManage(object):
     """"""
     """"""
@@ -38,24 +38,27 @@ class JobManage(object):
     @staticmethod
     @staticmethod
     def job101():
     def job101():
         """
         """
-        每日22点清理30天之前的日志
+        每日22点清理7天之前的日志
+
+        每日22点清理1天之前的日志(测试)
 
 
         todo 根据UserWorkRecordList.start_at来判断过去7天的数据
         todo 根据UserWorkRecordList.start_at来判断过去7天的数据
         """
         """
-        # --- get list ---
-        file_path_list = methods.get_file_path_list(save_dir)
-        file_name_list = [i.split('/')[-1] for i in file_path_list]
-        # methods.debug_log('JobManage44', f"#file_name_list: {file_name_list}")
+        # --- get log_file_uuid_list ---
+        log_file_list = methods.get_file_path_list(save_dir)
+        log_file_name_list = [i.split('\\')[-1] for i in log_file_list]
+        log_file_uuid_list = [i.split('.')[0] for i in log_file_name_list]
 
 
         # --- test ---
         # --- test ---
-        # for file_name in file_name_list:
-        #     file_path = os.path.join(save_dir, file_name)
-        #     if methods.is_file(file_path):
-        #         methods.remove_file(file_path)
-
-        # --- cut list ---
-        # remove_count = 30 * 24  # 按小时
-        # for file_name in file_name_list[remove_count:]:
-        #     file_path = os.path.join(save_dir, file_name)
-        #     if methods.is_file(file_path):
-        #         methods.remove_file(file_path)
+        for log_file_uuid in log_file_uuid_list:
+            
+            # --- check ---
+            file_path = os.path.join(save_dir, f"{log_file_uuid}.log")
+            item = Global.mdb.get_one_by_id('UserWorkRecordList', log_file_uuid)
+            if not item:
+                methods.remove_file(file_path)
+
+            # --- check ---
+            now_at = methods.now_ts()
+            if now_at > item.get('end_at') + 86400 * 1:
+                methods.remove_file(file_path)