JobManage.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from hub import Global, methods
  2. import os
  3. class JobManage(object):
  4. """"""
  5. # --- 接口认证信息 ---
  6. # username = '500A7062'
  7. # password = '198797#cjhxbin'
  8. @classmethod
  9. def run(cls):
  10. """启动全部任务"""
  11. # --- test ---
  12. # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3) # 循环测试
  13. # Global.aps.create_job(func=cls.job101, trigger='date', run_date='2022-02-23 18:54:00') # 定时测试
  14. # Global.aps.create_job(func=cls.job301, trigger='interval', seconds=60) # 循环测试
  15. # Global.aps.create_job(func=cls.job20102, trigger='date', run_date='2022-07-28 17:15:30') # 定时测试
  16. # Global.aps.create_job(func=cls.job101, trigger='cron', hour=22) # 每天晚10点
  17. # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=60) # 每1分钟
  18. # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=300) # 每5分钟
  19. # --- release ---
  20. Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3600) # 每1小时
  21. @classmethod
  22. def end(cls):
  23. """暂停全部任务"""
  24. Global.aps.pause_all()
  25. @staticmethod
  26. def job101():
  27. """
  28. 每1小时清理7*24小时之前的日志
  29. """
  30. # --- log ---
  31. methods.debug_log("JobManage|49", f"------------------------------ start job101")
  32. # --- get log_file_uuid_list ---
  33. log_file_list = methods.get_file_path_list(Global.save_dir)
  34. log_file_name_list = [i.split('\\')[-1] for i in log_file_list]
  35. log_file_uuid_list = [i.split('.')[0] for i in log_file_name_list]
  36. # --- test ---
  37. for log_file_uuid in log_file_uuid_list:
  38. # --- check ---
  39. file_path = os.path.join(Global.save_dir, f"{log_file_uuid}.log")
  40. item = Global.mdb.get_one_by_id('UserWorkRecordList', log_file_uuid)
  41. if not item:
  42. methods.remove_file(file_path)
  43. # --- check ---
  44. now_at = methods.now_ts()
  45. if now_at > item.get('end_at') + 86400 * 1:
  46. methods.remove_file(file_path)