JobManage.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from hub import Global, methods
  2. class JobManage(object):
  3. """"""
  4. # --- 接口认证信息 ---
  5. # username = '500A7062'
  6. # password = '198797#cjhxbin'
  7. @classmethod
  8. def run(cls):
  9. """启动全部任务"""
  10. # --- test ---
  11. # Global.aps.create_job(func=cls.job101, trigger='interval', seconds=3) # 循环测试
  12. # Global.aps.create_job(func=cls.job101, trigger='date', run_date='2022-02-23 18:54:00') # 定时测试
  13. # Global.aps.create_job(func=cls.job301, trigger='interval', seconds=60) # 循环测试
  14. # Global.aps.create_job(func=cls.job20102, trigger='date', run_date='2022-07-28 17:15:30') # 定时测试
  15. # --- release ---
  16. # Global.aps.create_job(func=cls.job101_on_windows, trigger='cron', hour=22) # 每天晚10点 release
  17. # Global.aps.create_job(func=cls.job20102, trigger='interval', seconds=600) # 每10分钟 release
  18. # Global.aps.create_job(func=cls.job301, trigger='interval', seconds=300) # 每5分钟 release
  19. @classmethod
  20. def end(cls):
  21. """暂停全部任务"""
  22. Global.aps.pause_all()
  23. @staticmethod
  24. def job101_on_windows():
  25. """
  26. 每日22点清理30天之前的日志
  27. """
  28. pass
  29. @staticmethod
  30. def job101_on_linux():
  31. """
  32. 每日22点清理30天之前的日志
  33. """
  34. # --- get list ---
  35. log_file_dir = f"/home/server/logs"
  36. file_path_list = methods.get_file_path_list(log_file_dir)
  37. file_name_list = [i.split('/')[-1] for i in file_path_list]
  38. # methods.debug_log('JobManage.job101.41', f"#file_name_list: {file_name_list}")
  39. # --- cut list ---
  40. for file_name in file_name_list[30:]:
  41. file_path = f"/home/server/logs/{file_name}"
  42. if methods.is_file(file_path):
  43. methods.remove_file(file_path)