12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from hub import Global, methods
- import os
- # --- for linux
- # save_dir = f'/home/server/logs'
- # --- for windows
- save_dir = r'C:\logs' # sri内网测试环境
- class JobManage(object):
- """"""
- # --- 接口认证信息 ---
- # username = '500A7062'
- # password = '198797#cjhxbin'
- @classmethod
- def run(cls):
- """启动全部任务"""
- # --- test ---
- # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3) # 循环测试
- # Global.aps.create_job(func=cls.job101, trigger='date', run_date='2022-02-23 18:54:00') # 定时测试
- # Global.aps.create_job(func=cls.job301, trigger='interval', seconds=60) # 循环测试
- # Global.aps.create_job(func=cls.job20102, trigger='date', run_date='2022-07-28 17:15:30') # 定时测试
- # Global.aps.create_job(func=cls.job101, trigger='cron', hour=22) # 每天晚10点
- # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=60) # 每1分钟
- # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=300) # 每5分钟
- # --- release ---
- Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3600) # 每1小时
- @classmethod
- def end(cls):
- """暂停全部任务"""
- Global.aps.pause_all()
- @staticmethod
- def job101():
- """
- 每1小时清理7*24小时之前的日志
- """
- # --- log ---
- methods.debug_log("JobManage|49", f"------------------------------ start job101")
- # --- 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 ---
- 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)
|