mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 13:59:24 +08:00
add: check alas prev status
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
import pathlib
|
||||
import threading
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
@@ -7,6 +8,7 @@ from typing import Dict
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.counter import MaxCounter
|
||||
from module.notify import handle_notify
|
||||
from module.submodule.utils import has_config_mod
|
||||
from module.webui.process_manager import ProcessManager
|
||||
|
||||
|
||||
@@ -18,6 +20,7 @@ class InstanceSetting:
|
||||
|
||||
|
||||
class InstanceWatcher:
|
||||
STATUS_DIR = "./bin/status"
|
||||
instance = None
|
||||
|
||||
def __init__(self):
|
||||
@@ -66,6 +69,28 @@ class InstanceWatcher:
|
||||
for i in ins_has_triggered:
|
||||
self.remove_instance(i)
|
||||
|
||||
def add_status_file(self, name):
|
||||
f = pathlib.Path(InstanceWatcher.STATUS_DIR) / f"{name}.status"
|
||||
if not f.exists():
|
||||
f.parent.mkdir(parents=True, exist_ok=True)
|
||||
f.touch()
|
||||
|
||||
def remove_status_file(self, name):
|
||||
f = pathlib.Path(InstanceWatcher.STATUS_DIR) / f"{name}.status"
|
||||
if f.exists():
|
||||
f.parent.mkdir(parents=True, exist_ok=True)
|
||||
f.unlink()
|
||||
|
||||
def get_all_prev_instance(self):
|
||||
f = pathlib.Path(InstanceWatcher.STATUS_DIR)
|
||||
if not f.exists():
|
||||
f.mkdir(parents=True, exist_ok=True)
|
||||
return [i.stem for i in f.glob("*.status")]
|
||||
|
||||
def has_status_file(self, name):
|
||||
f = pathlib.Path(InstanceWatcher.STATUS_DIR) / f"{name}.status"
|
||||
return f.exists()
|
||||
|
||||
def try_add_instance(self, name):
|
||||
if name in self.instances:
|
||||
return
|
||||
@@ -78,10 +103,22 @@ class InstanceWatcher:
|
||||
notify_config=full_config.Alas_Error_OnePushConfig
|
||||
)
|
||||
self.instances[name] = setting
|
||||
self.add_status_file(name)
|
||||
|
||||
def check_instance_status(self):
|
||||
for config_name in self.get_all_prev_instance():
|
||||
if not has_config_mod(config_name):
|
||||
continue
|
||||
ins = ProcessManager.get_manager(config_name)
|
||||
if ins.alive:
|
||||
continue
|
||||
if ins.detailed_instance_status == ProcessManager.DetailInstanceStatus.NoRenderables:
|
||||
ins.start("alas")
|
||||
|
||||
def remove_instance(self, name):
|
||||
try:
|
||||
self.instances.pop(name)
|
||||
self.remove_status_file(name)
|
||||
except Exception:
|
||||
...
|
||||
|
||||
@@ -91,6 +128,7 @@ class InstanceWatcher:
|
||||
try:
|
||||
self.check_counter()
|
||||
self.check_instances()
|
||||
self.check_instance_status()
|
||||
except Exception:
|
||||
...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user