feat(cleanup): remove the uploads size cap
The uploads size cap trimmed source uploads once UPLOAD_DIR crossed
UPLOADS_MAX_GB (default 15 GB), so a burst of long sources got purged
mid-window ("Uploads at 28.3 GB (cap 15 GB) — trimming"). Drop the cap
entirely: the function, the UPLOADS_MAX_GB env knob, its call in the
cleanup task and the scope test.
Sources are still bounded by the age-based _sweep_expired_uploads sweep
(they age out with JOB_RETENTION_SECONDS), and the OUTPUT_MAX_GB cap is
untouched.
This commit is contained in:
parent
963c3fb7c1
commit
fd4823ee7f
2 changed files with 1 additions and 46 deletions
|
|
@ -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.
|
# age-based sweep alone can't stop a burst of long videos from filling the disk.
|
||||||
# 0 disables the cap.
|
# 0 disables the cap.
|
||||||
OUTPUT_MAX_GB = int(os.environ.get("OUTPUT_MAX_GB", "25"))
|
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
|
# 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.
|
# 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"))
|
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
|
# 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
|
# 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(
|
JOB_RETENTION_SECONDS = int(
|
||||||
os.environ.get("JOB_RETENTION_SECONDS", "86400")
|
os.environ.get("JOB_RETENTION_SECONDS", "86400")
|
||||||
)
|
)
|
||||||
|
|
@ -1037,39 +1035,6 @@ def _sweep_expired_uploads(now):
|
||||||
pass
|
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():
|
def _enforce_output_size_cap():
|
||||||
"""Delete the oldest job dirs while OUTPUT_DIR is over OUTPUT_MAX_GB."""
|
"""Delete the oldest job dirs while OUTPUT_DIR is over OUTPUT_MAX_GB."""
|
||||||
cap = OUTPUT_MAX_GB * 1024 ** 3
|
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
|
# under the cap — clips are already archived to R2 and get restored
|
||||||
# on demand, so this only costs a re-download.
|
# on demand, so this only costs a re-download.
|
||||||
_enforce_output_size_cap()
|
_enforce_output_size_cap()
|
||||||
_enforce_uploads_size_cap()
|
|
||||||
|
|
||||||
# Agent upload slots: expire with their file (the file sweep below
|
# Agent upload slots: expire with their file (the file sweep below
|
||||||
# removes it; a slot whose file is gone or too old is dropped).
|
# removes it; a slot whose file is gone or too old is dropped).
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,3 @@ class TestUploadSweep:
|
||||||
app_module.jobs["done"] = {"status": "failed"}
|
app_module.jobs["done"] = {"status": "failed"}
|
||||||
app_module._sweep_expired_uploads(time.time())
|
app_module._sweep_expired_uploads(time.time())
|
||||||
assert not f.exists()
|
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()
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue