Files
feedmill-recounter/scripts/purge_expired_outputs.py
jetson 5e2a31792f feat: a finished job leaves one compressed video, expired after 5 days
The annotated output was kept uncompressed forever: a 20-minute clip left
a 724 MB file in output/job-*/, and the download route wrote a second
"_compressed.mp4" next to it (both kept).

Now the job compresses its own output when it finishes: the encode goes to
a temp file, is validated, and replaces the source atomically
(os.replace) under the SAME name. One video per job, the client never sees
a "_compressed" file, and the API's output_path stays valid. A failed
encode or a result that still overshoots the cap leaves the original
untouched, so nothing is ever lost.

The job videos are deleted 5 days after the job (scripts/purge_expired_
outputs.py, cron daily 03:17); the job dir, the thumbnail and the sample
frames stay, so the jobs list still renders.
2026-10-28 15:10:05 +07:00

43 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""Delete expired job videos from the output directory.
A finished job leaves exactly one video behind (the compressed one). This
script sweeps the videos that are older than the retention period, so the
disk does not fill up with jobs nobody will ever download again.
python scripts/purge_expired_outputs.py --output-dir output --max-age-days 5
The job directory, the thumbnail and the sample frames stay - the jobs list
in the web UI still renders.
"""
from __future__ import annotations
import argparse
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from src.compress import RETENTION_DAYS, purge_expired_media # noqa: E402
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--output-dir", default="output",
help="the job output root (default: output)")
parser.add_argument("--max-age-days", type=float, default=RETENTION_DAYS,
help=f"delete videos older than this (default: {RETENTION_DAYS})")
args = parser.parse_args(argv)
deleted = purge_expired_media(args.output_dir, max_age_days=args.max_age_days)
for path in deleted:
print(f"deleted {path}")
print(f"purged {len(deleted)} file(s) older than {args.max_age_days} days "
f"from {args.output_dir}")
return 0
if __name__ == "__main__":
raise SystemExit(main())