MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / repetition_check

Method repetition_check

task.py:2923–2955  ·  view source on GitHub ↗
(self, task: _Script)

Source from the content-addressed store, hash-verified

2921 self._tasks = None
2922
2923 def repetition_check(self, task: _Script) -> bool:
2924 real_cmd = task.cmd.strip()
2925 if real_cmd.startswith("nohup"):
2926 real_cmd = real_cmd[len("nohup"):].strip()
2927 if self._redirection_regexp.search(real_cmd):
2928 # 切分重定向
2929 real_cmd = self._redirection_regexp.split(real_cmd)[0].strip()
2930
2931 real_cmd_list = real_cmd.split(" ")
2932 for p in psutil.pids():
2933 try:
2934 if p == self._my_pid:
2935 continue
2936 proc = psutil.Process(p)
2937 cmd = proc.cmdline()
2938 if cmd[:len(real_cmd_list)] != real_cmd_list:
2939 continue
2940
2941 run_times = time.time() - proc.create_time()
2942 if run_times < task.interval:
2943 write_log("任务[{}]未达到运行间隔,跳过".format(task.name))
2944 return False
2945 if run_times < 10 * 60:
2946 write_log("任务【{}】执行拥塞,跳过本次执行".format(task.name), _level='error', color='red')
2947 return True
2948 else:
2949 write_log("任务【{}】执行超时,已杀死".format(task.name), _level='error', color='red')
2950 proc.kill()
2951 return False
2952 except Exception as e:
2953 continue
2954
2955 return False
2956
2957
2958 def start(self):

Callers 1

startMethod · 0.95

Calls 6

timeMethod · 0.80
killMethod · 0.80
write_logFunction · 0.70
searchMethod · 0.45
splitMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected