JobManage.py 1.8 KB

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