fix: 修复task多次开启问题
feat: 新增 891 参数(医院停早,红球靠外)
pref: 弃用 action 类
This commit is contained in:
bmy
2024-08-17 01:40:07 +08:00
parent 7ae8162da7
commit 91d6491f64
10 changed files with 1828 additions and 78 deletions

22
app.py
View File

@@ -23,7 +23,7 @@ processes = []
time_record = None
task_run_flag = False
# 日志队列
queue = Queue()
@@ -37,7 +37,9 @@ app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, allow_unsafe_werkzeug=True)
server_process = None
# FIXME 在列表里存所有的 task_process
task_process = None
task_run_flag = threading.Event()
class WebSocketHandler(logging.Handler):
def emit(self, record):
@@ -124,23 +126,23 @@ def operate_handle(data):
elif data['type'] == 'operate_task':
# 任务函数
if data['content'] == 'run':
task_run_flag = True
task_run_flag.set()
# 开启 task 进程前先关闭所有历史进程
if task_process != None:
task_process.terminate()
time_record = time.perf_counter()
task_process = Process(target=main_func, args=(queue,skip_task_queue))
task_process = Process(target=main_func, args=(task_run_flag,queue,skip_task_queue))
task_process.start()
logger.info("开启 task")
elif data['content'] == 'stop':
task_run_flag = False
task_process.terminate()
task_run_flag.clear()
if task_process != None:
task_process.terminate()
logger.info(f"任务结束 用时{time.perf_counter() - time_record}s")
logger.info("关闭 task")
elif data['content'] == 'restart':
if task_process != None:
task_process.terminate()
task_process = Process(target=main_func, args=(queue,skip_task_queue))
task_process.start()
pass
elif data['type'] == 'show_server_log':
content = ''
try:
@@ -167,7 +169,7 @@ def test_connect():
for item in fileOptions_list:
config_data[item] = toml.load(os.path.join(fileOptions_path,item))
socketio.emit('config_data', {'type': 'config_data', 'content': config_data})
socketio.emit('task_status', {'type': 'task_status', 'content': int(task_run_flag)})
socketio.emit('task_status', {'type': 'task_status', 'content': int(task_run_flag.isSet())})
def thread_function():
global queue
while True: