File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
354369def 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 )
You can’t perform that action at this time.
0 commit comments