JobManage.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from hub import Global, methods
  2. import os
  3. # --- for linux
  4. # save_dir = f'/home/server/logs'
  5. # --- for windows
  6. save_dir = r'C:\temp' # sri内网测试环境
  7. class JobManage(object):
  8. """"""
  9. # --- 接口认证信息 ---
  10. # username = '500A7062'
  11. # password = '198797#cjhxbin'
  12. @classmethod
  13. def run(cls):
  14. """启动全部任务"""
  15. # --- test ---
  16. # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3) # 循环测试
  17. # Global.aps.create_job(func=cls.job101, trigger='date', run_date='2022-02-23 18:54:00') # 定时测试
  18. # Global.aps.create_job(func=cls.job301, trigger='interval', seconds=60) # 循环测试
  19. # Global.aps.create_job(func=cls.job20102, trigger='date', run_date='2022-07-28 17:15:30') # 定时测试
  20. # --- release ---
  21. Global.aps.create_job(func=cls.job101, trigger='cron', hour=22) # 每天晚10点 release
  22. # Global.aps.create_job(func=cls.job20102, trigger='interval', seconds=600) # 每10分钟 release
  23. # Global.aps.create_job(func=cls.job301, trigger='interval', seconds=300) # 每5分钟 release
  24. @classmethod
  25. def end(cls):
  26. """暂停全部任务"""
  27. Global.aps.pause_all()
  28. @staticmethod
  29. def job101():
  30. """
  31. 每日22点清理30天之前的日志
  32. todo 根据UserWorkRecordList.start_at来判断过去7天的数据
  33. """
  34. # --- get list ---
  35. file_path_list = methods.get_file_path_list(save_dir)
  36. file_name_list = [i.split('/')[-1] for i in file_path_list]
  37. # methods.debug_log('JobManage44', f"#file_name_list: {file_name_list}")
  38. # --- test ---
  39. # for file_name in file_name_list:
  40. # file_path = os.path.join(save_dir, file_name)
  41. # if methods.is_file(file_path):
  42. # methods.remove_file(file_path)
  43. # --- cut list ---
  44. # remove_count = 30 # 按天
  45. remove_count = 30 * 24 # 按小时
  46. for file_name in file_name_list[remove_count:]:
  47. file_path = os.path.join(save_dir, file_name)
  48. if methods.is_file(file_path):
  49. methods.remove_file(file_path)