diff --git a/clipwright/api/app.py b/clipwright/api/app.py index 2bf1aa6..eeb3224 100644 --- a/clipwright/api/app.py +++ b/clipwright/api/app.py @@ -52,8 +52,6 @@ MAX_FILE_SIZE_MB = int(os.environ.get("MAX_FILE_SIZE_MB", "0") or "0") # age-based sweep alone can't stop a burst of long videos from filling the disk. # 0 disables the cap. OUTPUT_MAX_GB = int(os.environ.get("OUTPUT_MAX_GB", "25")) -# Same idea for source uploads, which are the biggest single files on disk. -UPLOADS_MAX_GB = int(os.environ.get("UPLOADS_MAX_GB", "15")) # Pre-flight quality gate: warn before processing a YouTube source below this # height (0 disables). Only applies to URLs; uploads are whatever the user gave. QUALITY_GATE_MIN_HEIGHT = int(os.environ.get("QUALITY_GATE_MIN_HEIGHT", "720")) @@ -116,7 +114,7 @@ for _stream in (sys.stdout, sys.stderr): # Job/file retention (issue #46). Self-host defaults to 24h: the 1h sweep kept # deleting finished projects under users who never touched their env, and the -# OUTPUT_MAX_GB / UPLOADS_MAX_GB caps below already bound the disk. +# OUTPUT_MAX_GB cap below already bounds the disk. JOB_RETENTION_SECONDS = int( os.environ.get("JOB_RETENTION_SECONDS", "86400") ) @@ -1037,39 +1035,6 @@ def _sweep_expired_uploads(now): pass -def _enforce_uploads_size_cap(): - """Delete the oldest source uploads while UPLOAD_DIR is over UPLOADS_MAX_GB. - - Sources are only needed while a job runs (and for the preview afterwards), - but they're the biggest files on disk โ€” up to MAX_FILE_SIZE_MB each. - """ - cap = UPLOADS_MAX_GB * 1024 ** 3 - if cap <= 0: - return - used = _dir_size(UPLOAD_DIR) - if used <= cap: - return - files = [] - for name in os.listdir(UPLOAD_DIR): - p = os.path.join(UPLOAD_DIR, name) - if os.path.isfile(p) and not _job_is_active(_upload_job_id(name)): - try: - files.append((os.path.getmtime(p), p, os.path.getsize(p))) - except OSError: - pass - files.sort() - print(f"๐Ÿงน Uploads at {used / 1024**3:.1f} GB (cap {UPLOADS_MAX_GB} GB) โ€” trimming.") - for _mtime, path, size in files: - if used <= cap: - break - try: - os.remove(path) - used -= size - print(f"๐Ÿงน Size cap: removed upload {os.path.basename(path)}") - except OSError: - pass - - def _enforce_output_size_cap(): """Delete the oldest job dirs while OUTPUT_DIR is over OUTPUT_MAX_GB.""" cap = OUTPUT_MAX_GB * 1024 ** 3 @@ -1153,7 +1118,6 @@ async def cleanup_jobs(): # under the cap โ€” clips are already archived to R2 and get restored # on demand, so this only costs a re-download. _enforce_output_size_cap() - _enforce_uploads_size_cap() # Agent upload slots: expire with their file (the file sweep below # removes it; a slot whose file is gone or too old is dropped). diff --git a/tests/test_cleanup_live_jobs.py b/tests/test_cleanup_live_jobs.py index e0696a1..1ffae99 100644 --- a/tests/test_cleanup_live_jobs.py +++ b/tests/test_cleanup_live_jobs.py @@ -117,12 +117,3 @@ class TestUploadSweep: app_module.jobs["done"] = {"status": "failed"} app_module._sweep_expired_uploads(time.time()) assert not f.exists() - - def test_size_cap_skips_live_sources(self, disk, monkeypatch): - _, up = disk - live = _upload(up, "live") - app_module._running_jobs.add("live") - dead = _upload(up, "dead") - monkeypatch.setattr(app_module, "UPLOADS_MAX_GB", 1 / 1024 ** 3) - app_module._enforce_uploads_size_cap() - assert live.exists() and not dead.exists()