Spaces:
Paused
Paused
Fix JOB_EXPIRED: BASE persistence, bootstrap order, remove duplicates
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ HISTORY_LOCK = threading.Lock()
|
|
| 31 |
SEMAPHORE = threading.Semaphore(3)
|
| 32 |
|
| 33 |
# ββ Imp-1: Job persistence β survives space restart/sleep βββββββββββββββββββββ
|
| 34 |
-
JOBS_FILE =
|
| 35 |
|
| 36 |
def _save_jobs():
|
| 37 |
"""Persist active jobs to disk (excludes locks and file handles)."""
|
|
@@ -261,9 +261,6 @@ def upload():
|
|
| 261 |
if "file" not in request.files:
|
| 262 |
return jsonify({"error": "no file"}), 400
|
| 263 |
content_length = request.content_length or 0
|
| 264 |
-
if content_length > 0 and not _check_disk_free(content_length * 2):
|
| 265 |
-
return jsonify({"error": "server disk full β try later"}), 503 # Imp-D
|
| 266 |
-
content_length = request.content_length or 0
|
| 267 |
if content_length > 0 and not _check_disk_free(content_length * 2):
|
| 268 |
return jsonify({"error": "server disk full β try later"}), 503 # Imp-D
|
| 269 |
f = request.files["file"]
|
|
@@ -421,7 +418,6 @@ def _run_engine(job_id):
|
|
| 421 |
"--iterations", "3"]
|
| 422 |
for rf in ref_files[:3]: cmd += ["--ref", str(rf)]
|
| 423 |
_ENGINE_TIMEOUT = 25 * 60 # Imp-B: 25min hard limit
|
| 424 |
-
_ENGINE_TIMEOUT = 25 * 60 # Imp-B: 25min hard limit
|
| 425 |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
| 426 |
stderr=subprocess.STDOUT, text=True)
|
| 427 |
engine_log = []
|
|
@@ -566,12 +562,7 @@ def history():
|
|
| 566 |
with HISTORY_LOCK: snapshot = list(HISTORY)
|
| 567 |
return jsonify({"jobs": snapshot})
|
| 568 |
|
| 569 |
-
if __name__ == "__main__":
|
| 570 |
-
port = int(os.environ.get("PORT", 7860))
|
| 571 |
-
app.run(host="0.0.0.0", port=port, threaded=True)
|
| 572 |
-
|
| 573 |
# S68: auto-download missing engine files from GitHub on startup
|
| 574 |
-
# S146: updated β v21 replaces v12; dead engines v87/v84/v89 removed
|
| 575 |
def _bootstrap_engines():
|
| 576 |
import urllib.request
|
| 577 |
RAW = "https://raw.githubusercontent.com/hammer24678-star/tilawa-enhancer-/master/assets/engines"
|
|
@@ -593,4 +584,8 @@ def _bootstrap_engines():
|
|
| 593 |
except Exception as ex:
|
| 594 |
print(f"[bootstrap] failed {e}: {ex}")
|
| 595 |
|
| 596 |
-
threading.Thread(target=_bootstrap_engines, daemon=True).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
SEMAPHORE = threading.Semaphore(3)
|
| 32 |
|
| 33 |
# ββ Imp-1: Job persistence β survives space restart/sleep βββββββββββββββββββββ
|
| 34 |
+
JOBS_FILE = BASE / "tilawa_jobs.json"
|
| 35 |
|
| 36 |
def _save_jobs():
|
| 37 |
"""Persist active jobs to disk (excludes locks and file handles)."""
|
|
|
|
| 261 |
if "file" not in request.files:
|
| 262 |
return jsonify({"error": "no file"}), 400
|
| 263 |
content_length = request.content_length or 0
|
|
|
|
|
|
|
|
|
|
| 264 |
if content_length > 0 and not _check_disk_free(content_length * 2):
|
| 265 |
return jsonify({"error": "server disk full β try later"}), 503 # Imp-D
|
| 266 |
f = request.files["file"]
|
|
|
|
| 418 |
"--iterations", "3"]
|
| 419 |
for rf in ref_files[:3]: cmd += ["--ref", str(rf)]
|
| 420 |
_ENGINE_TIMEOUT = 25 * 60 # Imp-B: 25min hard limit
|
|
|
|
| 421 |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
| 422 |
stderr=subprocess.STDOUT, text=True)
|
| 423 |
engine_log = []
|
|
|
|
| 562 |
with HISTORY_LOCK: snapshot = list(HISTORY)
|
| 563 |
return jsonify({"jobs": snapshot})
|
| 564 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
# S68: auto-download missing engine files from GitHub on startup
|
|
|
|
| 566 |
def _bootstrap_engines():
|
| 567 |
import urllib.request
|
| 568 |
RAW = "https://raw.githubusercontent.com/hammer24678-star/tilawa-enhancer-/master/assets/engines"
|
|
|
|
| 584 |
except Exception as ex:
|
| 585 |
print(f"[bootstrap] failed {e}: {ex}")
|
| 586 |
|
| 587 |
+
threading.Thread(target=_bootstrap_engines, daemon=True).start()
|
| 588 |
+
|
| 589 |
+
if __name__ == "__main__":
|
| 590 |
+
port = int(os.environ.get("PORT", 7860))
|
| 591 |
+
app.run(host="0.0.0.0", port=port, threaded=True)
|