carm5333 commited on
Commit
323a394
·
verified ·
1 Parent(s): 0470bb8

S147: dedup TMP + job/engine timeout + health RAM/disk + upload guard + richer errors

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -17,13 +17,6 @@ app = Flask(__name__)
17
  CORS(app)
18
  app.config["MAX_CONTENT_LENGTH"] = 512 * 1024 * 1024 # S146: 512MB — supports up to 200MB files
19
 
20
- TMP = Path(tempfile.gettempdir()) # S147-fix: moved before JOBS block
21
- UPLOAD_DIR = TMP / "tilawa_uploads"
22
- CHUNK_DIR = TMP / "tilawa_chunks"
23
- OUTPUT_DIR = TMP / "tilawa_outputs"
24
- for _d in [UPLOAD_DIR, CHUNK_DIR, OUTPUT_DIR]:
25
- _d.mkdir(exist_ok=True)
26
-
27
  TMP = Path(tempfile.gettempdir()) # S147-fix: moved before JOBS block
28
  UPLOAD_DIR = TMP / "tilawa_uploads"
29
  CHUNK_DIR = TMP / "tilawa_chunks"
@@ -268,6 +261,9 @@ def upload():
268
  if "file" not in request.files:
269
  return jsonify({"error": "no file"}), 400
270
  content_length = request.content_length or 0
 
 
 
271
  if content_length > 0 and not _check_disk_free(content_length * 2):
272
  return jsonify({"error": "server disk full — try later"}), 503 # Imp-D
273
  f = request.files["file"]
@@ -425,6 +421,7 @@ def _run_engine(job_id):
425
  "--iterations", "3"]
426
  for rf in ref_files[:3]: cmd += ["--ref", str(rf)]
427
  _ENGINE_TIMEOUT = 25 * 60 # Imp-B: 25min hard limit
 
428
  proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
429
  stderr=subprocess.STDOUT, text=True)
430
  engine_log = []
 
17
  CORS(app)
18
  app.config["MAX_CONTENT_LENGTH"] = 512 * 1024 * 1024 # S146: 512MB — supports up to 200MB files
19
 
 
 
 
 
 
 
 
20
  TMP = Path(tempfile.gettempdir()) # S147-fix: moved before JOBS block
21
  UPLOAD_DIR = TMP / "tilawa_uploads"
22
  CHUNK_DIR = TMP / "tilawa_chunks"
 
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
  "--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 = []