调整任务执行模式
This commit is contained in:
parent
b5ab089fb3
commit
6ae548757a
|
@ -97,7 +97,7 @@ def battle_logic(baseline : Baseline, battle : Battle):
|
||||||
|
|
||||||
def tick():
|
def tick():
|
||||||
try:
|
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:
|
for battle in battles:
|
||||||
battle.status = -1
|
battle.status = -1
|
||||||
battle.save()
|
battle.save()
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
|
||||||
from peewee import JOIN
|
from peewee import JOIN
|
||||||
|
|
||||||
|
@ -19,9 +21,6 @@ Model.create_table()
|
||||||
Battle.create_table()
|
Battle.create_table()
|
||||||
Baseline.create_table()
|
Baseline.create_table()
|
||||||
|
|
||||||
threadpool = ThreadPoolExecutor(1)
|
|
||||||
|
|
||||||
|
|
||||||
EnvCard2RealCard = {3: '3', 4: '4', 5: '5', 6: '6', 7: '7',
|
EnvCard2RealCard = {3: '3', 4: '4', 5: '5', 6: '6', 7: '7',
|
||||||
8: '8', 9: '9', 10: 'T', 11: 'J', 12: 'Q',
|
8: '8', 9: '9', 10: 'T', 11: 'J', 12: 'Q',
|
||||||
13: 'K', 14: 'A', 17: '2', 20: 'X', 30: 'D'}
|
13: 'K', 14: 'A', 17: '2', 20: 'X', 30: 'D'}
|
||||||
|
@ -49,9 +48,17 @@ def upload():
|
||||||
model_file.save(path)
|
model_file.save(path)
|
||||||
Model.create(path=path, position=position,type=type,frame=frame,create_time=datetime.now())
|
Model.create(path=path, position=position,type=type,frame=frame,create_time=datetime.now())
|
||||||
Battle.create(challenger_path=path, challenger_position=position, status=0)
|
Battle.create(challenger_path=path, challenger_position=position, status=0)
|
||||||
threadpool.submit(tick)
|
|
||||||
return jsonify({'status': 0, 'message': 'success', 'result': ''})
|
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'])
|
@app.route('/battle_tick', methods=['POST'])
|
||||||
def battle_tick():
|
def battle_tick():
|
||||||
tick()
|
tick()
|
||||||
|
|
Loading…
Reference in New Issue