diff --git a/app/jobs/sources.py b/app/jobs/sources.py index fd1e0f1..26b6daf 100644 --- a/app/jobs/sources.py +++ b/app/jobs/sources.py @@ -19,7 +19,7 @@ from typing import TYPE_CHECKING, Any from app.config import Config from app.models import Subscription, company_key from app.storage import Store -from app.jobs.pull import search_target +from app.jobs.pull import FAILING, search_target if TYPE_CHECKING: from app.jobs.discover import Discovery @@ -82,9 +82,12 @@ def set_board(store: Store, key: str, board: str, *, name: str = "", else: writes.setdefault("careers_url", careers_url(board)) writes.update(ats=host, ats_slug=slug) + before = store.company_subscription(key) _company, sub, closed = store.set_company_board(key, board, host=host, name=name, fields=writes) assert sub is not None + if before is not None and before.target != board: + _forget_failing(store, before.target) return sub, None if rows is None else len(rows), closed @@ -99,9 +102,17 @@ def detach_board(store: Store, key: str) -> int: if sub is None or not sub.show: raise ValueError(f"{key} has no board to detach") _company, _sub, closed = store.set_company_board(key, "") + _forget_failing(store, sub.target) return closed +def _forget_failing(store: Store, target: str) -> None: + """Drop what the pull recorded about a board nobody reads any more: a + record of `target` failing would otherwise outlive the board, and count + in `app companies check` for good.""" + store.state.pop(FAILING + target, None) + + def add_board(store: Store, board: str, name: str) -> tuple[Subscription, int]: """Follow one company by its ATS board: `set_board` keyed by `name`, so a company that exists gets the board attached or replaced. Returns the diff --git a/tests/test_sources.py b/tests/test_sources.py index 01d5b0e..edea9e1 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -287,3 +287,19 @@ def test_cli_seed_prints_counts_and_problems( captured = capsys.readouterr() assert json.loads(captured.out) == {"added": 1, "boards": 0, "skipped": 0, "total": 1} assert "companies seed: odd: 'nosuch:odd' is not a known board" in captured.err + + +def test_replacing_or_detaching_a_board_forgets_that_it_was_failing( + store: Store, boards: Boards) -> None: + from app.jobs.pull import FAILING, failing_boards + + sources.set_board(store, "acme", "greenhouse:acme", name="Acme") + store.state[FAILING + "greenhouse:acme"] = '{"since": "2026-09-01T00:00:00+00:00", "reason": "404 Not Found"}' + assert "greenhouse:acme" in failing_boards(store) + + sources.set_board(store, "acme", "ashby:acme") + assert failing_boards(store) == {} + + store.state[FAILING + "ashby:acme"] = '{"since": "2026-09-01T00:00:00+00:00", "reason": "timeout"}' + sources.detach_board(store, "acme") + assert failing_boards(store) == {}