调整任务执行模式

This commit is contained in:
zhiyang7 2021-12-28 09:18:33 +08:00
parent b5ab089fb3
commit 6ae548757a
2 changed files with 12 additions and 5 deletions

View File

@ -97,7 +97,7 @@ def battle_logic(baseline : Baseline, battle : Battle):
def tick():
try:
battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.desc()).limit(10)
battles = Battle.select().where(Battle.status == 0).order_by(Battle.id.asc()).limit(1)
for battle in battles:
battle.status = -1
battle.save()

View File

@ -1,5 +1,7 @@
import itertools
import os
import time
import threading
from peewee import JOIN
@ -19,9 +21,6 @@ Model.create_table()
Battle.create_table()
Baseline.create_table()
threadpool = ThreadPoolExecutor(1)
EnvCard2RealCard = {3: '3', 4: '4', 5: '5', 6: '6', 7: '7',
8: '8', 9: '9', 10: 'T', 11: 'J', 12: 'Q',
13: 'K', 14: 'A', 17: '2', 20: 'X', 30: 'D'}
@ -49,9 +48,17 @@ def upload():
model_file.save(path)
Model.create(path=path, position=position,type=type,frame=frame,create_time=datetime.now())
Battle.create(challenger_path=path, challenger_position=position, status=0)
threadpool.submit(tick)
return jsonify({'status': 0, 'message': 'success', 'result': ''})
def start_runner():
def start_loop():
while True:
tick()
time.sleep(10)
thread = threading.Thread(target=start_loop)
thread.start()
@app.route('/battle_tick', methods=['POST'])
def battle_tick():
tick()