Prune old job executions
All checks were successful
buildbot/nix-eval Build done.
buildbot/nix-build Build done.
buildbot/nix-effects Build done.

This commit is contained in:
Abel Luck 2026-06-02 11:31:39 +02:00
parent 813f19f355
commit 710ac76192
6 changed files with 552 additions and 11 deletions

View file

@ -67,6 +67,7 @@ def test_parse_args_supports_cleanup_media_defaults() -> None:
assert command == "cleanup-media"
assert args.config is None
assert args.feeds_dir is None
assert args.log_dir is None
assert args.days == 25
assert args.dry_run is False
@ -84,7 +85,24 @@ def test_entrypoint_runs_cleanup_media(monkeypatch, tmp_path) -> None:
recorded["media_dirs"] = media_dirs
return FakeResult()
def fake_cleanup_job_executions(
*,
log_dir,
successful_days,
unsuccessful_days,
dry_run,
):
recorded["log_dir"] = log_dir
recorded["successful_days"] = successful_days
recorded["unsuccessful_days"] = unsuccessful_days
recorded["job_dry_run"] = dry_run
return FakeResult()
monkeypatch.setattr("repub.entrypoint.cleanup_media", fake_cleanup_media)
monkeypatch.setattr(
"repub.entrypoint.cleanup_job_executions",
fake_cleanup_job_executions,
)
exit_code = entrypoint(
[
@ -103,6 +121,10 @@ def test_entrypoint_runs_cleanup_media(monkeypatch, tmp_path) -> None:
"retention_days": 10,
"dry_run": True,
"media_dirs": ("images", "audio", "video", "files"),
"log_dir": tmp_path / "logs",
"successful_days": 7,
"unsuccessful_days": 90,
"job_dry_run": True,
}
@ -139,7 +161,24 @@ REPUBLISHER_FILE_DIR = "files-custom"
recorded["media_dirs"] = media_dirs
return FakeResult()
def fake_cleanup_job_executions(
*,
log_dir,
successful_days,
unsuccessful_days,
dry_run,
):
recorded["log_dir"] = log_dir
recorded["successful_days"] = successful_days
recorded["unsuccessful_days"] = unsuccessful_days
recorded["job_dry_run"] = dry_run
return FakeResult()
monkeypatch.setattr("repub.entrypoint.cleanup_media", fake_cleanup_media)
monkeypatch.setattr(
"repub.entrypoint.cleanup_job_executions",
fake_cleanup_job_executions,
)
exit_code = entrypoint(["cleanup-media", "--config", str(config_path)])
@ -154,6 +193,61 @@ REPUBLISHER_FILE_DIR = "files-custom"
"videos-custom",
"files-custom",
),
"log_dir": tmp_path / "mirror" / "logs",
"successful_days": 7,
"unsuccessful_days": 90,
"job_dry_run": False,
}
def test_entrypoint_cleanup_media_accepts_log_dir_override(
monkeypatch, tmp_path
) -> None:
recorded: dict[str, object] = {}
class FakeResult:
failures = 0
def fake_cleanup_media(*, feeds_dir, retention_days, dry_run, media_dirs):
recorded["feeds_dir"] = feeds_dir
return FakeResult()
def fake_cleanup_job_executions(
*,
log_dir,
successful_days,
unsuccessful_days,
dry_run,
):
recorded["log_dir"] = log_dir
recorded["successful_days"] = successful_days
recorded["unsuccessful_days"] = unsuccessful_days
recorded["dry_run"] = dry_run
return FakeResult()
monkeypatch.setattr("repub.entrypoint.cleanup_media", fake_cleanup_media)
monkeypatch.setattr(
"repub.entrypoint.cleanup_job_executions",
fake_cleanup_job_executions,
)
exit_code = entrypoint(
[
"cleanup-media",
"--feeds-dir",
str(tmp_path / "feeds"),
"--log-dir",
str(tmp_path / "custom-logs"),
]
)
assert exit_code == 0
assert recorded == {
"feeds_dir": tmp_path / "feeds",
"log_dir": tmp_path / "custom-logs",
"successful_days": 7,
"unsuccessful_days": 90,
"dry_run": False,
}