Fix disappearing artifacts and guard against empty builds

The agent's background build threads called jsonify()/send_file() with no
Flask app context, so after a successful build they crashed with
'Working outside of application context', which triggered the error
handler that rmtree'd the whole build dir before the controller could
download the artifact. Wrap both runners in app.app_context().

Also guard all three layers against empty results: the agent refuses to
report success or serve a zip when dist/ has no files, and the scheduler
flags a downloaded empty zip as a failure rather than marking the job
done.
This commit is contained in:
Brett Williams
2026-08-31 10:07:04 -05:00
parent 1faa544ead
commit f73a5bbb2f
2 changed files with 21 additions and 4 deletions
+7
View File
@@ -3,6 +3,7 @@ import logging
import os
import threading
import time
import zipfile
import requests
@@ -225,6 +226,12 @@ class Scheduler:
for chunk in resp.iter_content(chunk_size=8192):
f.write(chunk)
with zipfile.ZipFile(dest) as zf:
files = [n for n in zf.namelist() if not n.endswith("/")]
if not files:
os.remove(dest)
raise RuntimeError(f"Worker {worker['url']} returned an empty artifact zip for {worker_job_id}")
db.update_job(job_id, artifacts=[fname])
# ---- logging / status -------------------------------------------------