WebHost: Give user feedback if generator failed.
This commit is contained in:
parent
39f85aa291
commit
e76887d0bf
|
@ -77,11 +77,6 @@ def handle_generation_failure(result: BaseException):
|
||||||
|
|
||||||
|
|
||||||
def launch_generator(pool: multiprocessing.pool.Pool, generation: Generation):
|
def launch_generator(pool: multiprocessing.pool.Pool, generation: Generation):
|
||||||
@db_session
|
|
||||||
def handle_fail(result: BaseException):
|
|
||||||
generation.state = STATE_ERROR
|
|
||||||
handle_generation_failure(result)
|
|
||||||
|
|
||||||
logging.info(f"Generating {generation.id} for {len(generation.options)} players")
|
logging.info(f"Generating {generation.id} for {len(generation.options)} players")
|
||||||
|
|
||||||
pool.apply_async(gen_game, (generation.options,),
|
pool.apply_async(gen_game, (generation.options,),
|
||||||
|
|
|
@ -48,6 +48,7 @@ def generate(race=False):
|
||||||
|
|
||||||
|
|
||||||
def gen_game(gen_options, race=False, owner=None, sid=None):
|
def gen_game(gen_options, race=False, owner=None, sid=None):
|
||||||
|
try:
|
||||||
target = tempfile.TemporaryDirectory()
|
target = tempfile.TemporaryDirectory()
|
||||||
playercount = len(gen_options)
|
playercount = len(gen_options)
|
||||||
seed = get_seed()
|
seed = get_seed()
|
||||||
|
@ -87,6 +88,10 @@ def gen_game(gen_options, race=False, owner=None, sid=None):
|
||||||
ERmain(erargs, seed)
|
ERmain(erargs, seed)
|
||||||
|
|
||||||
return upload_to_db(target.name, owner, sid)
|
return upload_to_db(target.name, owner, sid)
|
||||||
|
except BaseException:
|
||||||
|
with db_session:
|
||||||
|
Generation.get(id=sid).state = STATE_ERROR
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
@app.route('/wait/<suuid:seed>')
|
@app.route('/wait/<suuid:seed>')
|
||||||
|
@ -121,9 +126,9 @@ def upload_to_db(folder, owner, sid):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
flash(e)
|
flash(e)
|
||||||
if multidata:
|
if multidata:
|
||||||
|
with db_session:
|
||||||
seed = Seed(multidata=multidata, spoiler=spoiler, patches=patches, owner=owner, id=sid)
|
seed = Seed(multidata=multidata, spoiler=spoiler, patches=patches, owner=owner, id=sid)
|
||||||
for patch in patches:
|
for patch in patches:
|
||||||
patch.seed = seed
|
patch.seed = seed
|
||||||
Generation.get(id=sid).delete()
|
Generation.get(id=sid).delete()
|
||||||
commit()
|
|
||||||
return seed.id
|
return seed.id
|
||||||
|
|
Loading…
Reference in New Issue