Skip to content

Commit 309fd59

Browse files
author
Nils Bars
committed
Reset build state of stuck exercise builds on start
Fixes #23
1 parent 5d6dff3 commit 309fd59

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

webapp/ref/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,21 @@ def create_ssh_proxy(config=None):
350350
from ref.proxy import server_loop
351351
server_loop(app)
352352

353+
354+
def fix_stuck_exercise_builds(app: Flask):
355+
"""
356+
Resets any exercises that are stuck in BUILDING status back to NOT_BUILD.
357+
This can happen if the server was restarted during a build.
358+
"""
359+
with app.app_context():
360+
from ref.model import Exercise, ExerciseBuildStatus
361+
stuck = Exercise.query.filter_by(build_job_status=ExerciseBuildStatus.BUILDING).all()
362+
if stuck:
363+
for ex in stuck:
364+
ex.build_job_status = ExerciseBuildStatus.NOT_BUILD
365+
app.db.session.commit()
366+
app.logger.warning(f"Reset {len(stuck)} exercises from BUILDING to NOT_BUILD on startup.")
367+
353368
@flask_failsafe
354369
def create_app(config=None):
355370
"""
@@ -396,6 +411,7 @@ def create_app(config=None):
396411

397412
# Must happen after we have db access, since the credentails are store inthere.
398413
setup_telegram_logger(app)
414+
fix_stuck_exercise_builds(app)
399415

400416
setup_login(app)
401417
setup_instances(app)

0 commit comments

Comments
 (0)