(self, operation: str)
| 412 | # 运行一个Group相关的函数 |
| 413 | # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ |
| 414 | def run_operation(self, operation: str) -> Optional[str]: |
| 415 | pid_file = "{}/{}.pid".format(Group.GROUP_TMP_DIR, self.group_id) |
| 416 | |
| 417 | if operation not in ("start", "stop"): |
| 418 | return "指定的操作不存在" |
| 419 | |
| 420 | try: |
| 421 | p = psutil.Process(public.readFile(pid_file)) |
| 422 | if p.is_running(): |
| 423 | return "操作运行中, 请等待上一个操作执行完成" |
| 424 | except: |
| 425 | pass |
| 426 | |
| 427 | if os.path.exists(pid_file): |
| 428 | os.remove(pid_file) |
| 429 | |
| 430 | self.build_run_sort(reverse=(operation == "stop")) |
| 431 | self.save_running_data() |
| 432 | panel_path = "/www/server/panel" |
| 433 | public.ExecShell( |
| 434 | "nohup {}/pyenv/bin/python3 {}/mod/project/java/group_script.py {} {} &> /tmp/group_script.log & \n" |
| 435 | "echo $! > {} ".format( |
| 436 | panel_path, panel_path, operation, self.group_id, pid_file) |
| 437 | ) |
| 438 | return None |
| 439 | |
| 440 | def build_run_sort(self, reverse=False) -> List[List[dict]]: |
| 441 | projects = self.config["projects"] # type: List[Dict[str, Union[int, str, dict]]] |
no test coverage detected