Files
libretro/scripts/freshness/stalejob.py
T

41 lines
1.1 KiB
Python

"""The refresh job a stale row becomes and its result."""
from __future__ import annotations
from collections.abc import Sequence
from dataclasses import dataclass
from pathlib import Path
from core.paths import REPO_ROOT
LOG_DIR = REPO_ROOT / "tmp" / "refresh_stale"
@dataclass(frozen=True)
class Job:
"""One refresh action derived from a stale finding."""
area: str
subject: str
command: list[str]
log_path: Path
# Commands run after `command`, in order, only while each one succeeds.
then: tuple[tuple[str, ...], ...] = ()
# Platforms whose rescrape job must end before this one starts.
after: frozenset[str] = frozenset()
@dataclass(frozen=True)
class JobResult:
job: Job
returncode: int
duration: float
tail: str # last non-empty line of stderr or stdout
# (command, what it printed) for each command that ran, in order.
outputs: tuple[tuple[tuple[str, ...], str], ...] = ()
def output_of(self, command: Sequence[str]) -> str:
"""What *command* printed in this job, empty when it did not run."""
return next((text for ran, text in self.outputs if ran == tuple(command)), "")