Ask before a destructive board or search switch; queue a pull after a reopening one

Switching a company's board or a job board search off, replacing a
company's board and detaching one all close open roles in a tap; each
now asks first, naming the count (a replace also names the old and the
new board), the same as removing a search and deleting an agent
already do.

Switching a target back on, following a board, setting a board and
saving a search used to show nothing until the schedule's next pull,
up to six hours later. Each now queues a pull job right in the API
route, so the CLI and any other caller of the same endpoint behave
like the page; the queued pull's own refusal while one is already
running is not surfaced as an error.

Co-Authored-By: Claude Sonnet <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet committed 2026-09-29 15:18:16 +02:00
1 parent 92ff2bc069
commit e6be593542
6 files changed
+143 -23

No files matched your search

+29 -9
View File
@@ -324,16 +324,21 @@ class CompanyBoardBody(BaseModel):
@router.post("/companies/{key}/board")
def set_company_board(key: str, body: CompanyBoardBody, store: StoreDep) -> dict[str, Any]:
def set_company_board(key: str, body: CompanyBoardBody, store: StoreDep,
queue: QueueDep) -> dict[str, Any]:
"""Attach a board to a company, or replace the one it has. The board is
fetched first and refused if it does not answer; replacing closes the
old board's open roles."""
old board's open roles. Queues a pull right after, so the board is read
by the one already running or the very next one rather than the
schedule, up to six hours later; a refusal because one is already
running is not an error, see `app.jobs.pull.claim_run`."""
if store.company(key) is None:
raise HTTPException(404, f"no such company: {key}")
try:
sub, found, closed = jobs.sources.set_board(store, key, body.board)
except ValueError as exc:
raise HTTPException(422, str(exc)) from exc
queue.enqueue("pull")
return {"source": _one_source(store, sub.id), "found": found, "closed": closed}
@@ -429,12 +434,18 @@ class SwitchBody(BaseModel):
@router.post("/sources/{sub_id}/switch")
def switch_source(sub_id: int, body: SwitchBody, store: StoreDep) -> dict[str, Any]:
"""On or off for the next pull. Off closes the open roles at once; on
reopens the ones the next pull still finds."""
def switch_source(sub_id: int, body: SwitchBody, store: StoreDep,
queue: QueueDep) -> dict[str, Any]:
"""On or off. Off closes the open roles at once; on queues a pull right
after, so the ones it still lists reopen once the pull that is already
running reads it, or the very next one does, rather than waiting for the
schedule, up to six hours later. A refusal because one is already
running is not an error, see `app.jobs.pull.claim_run`."""
if store.subscription(sub_id) is None:
raise HTTPException(404, f"no such board or search: {sub_id}")
_, closed = jobs.sources.set_fetch(store, sub_id, body.on)
if body.on:
queue.enqueue("pull")
return {"source": _one_source(store, sub_id), "closed": closed}
@@ -471,14 +482,19 @@ def try_search(body: SearchBody, config: ConfigDep) -> dict[str, Any]:
@router.post("/searches")
def save_search(body: SearchBody, store: StoreDep, config: ConfigDep) -> dict[str, Any]:
def save_search(body: SearchBody, store: StoreDep, config: ConfigDep,
queue: QueueDep) -> dict[str, Any]:
"""Save a search, or update the one of that provider and name. It is run
once first and refused if it finds nothing."""
once first and refused if it finds nothing. Queues a pull right after,
so its roles are read by the one already running or the very next one
rather than the schedule, up to six hours later; a refusal because one is
already running is not an error, see `app.jobs.pull.claim_run`."""
try:
sub, found, complete = jobs.sources.save_search(config, store, body.provider,
body.name, _params(body))
except ValueError as exc:
raise HTTPException(422, str(exc)) from exc
queue.enqueue("pull")
return {"source": _one_source(store, sub.id), "found": found, "complete": complete}
@@ -497,14 +513,18 @@ class BoardBody(BaseModel):
@router.post("/boards", status_code=201)
def add_board(body: BoardBody, store: StoreDep) -> dict[str, Any]:
def add_board(body: BoardBody, store: StoreDep, queue: QueueDep) -> dict[str, Any]:
"""Follow a company by its ATS board: `set_board` keyed by the name, so
an existing company gets it attached or replaced. The board is fetched
first and refused if it does not answer."""
first and refused if it does not answer. Queues a pull right after, so
its roles are read by the one already running or the very next one
rather than the schedule, up to six hours later; a refusal because one is
already running is not an error, see `app.jobs.pull.claim_run`."""
try:
sub, found = jobs.sources.add_board(store, body.board, body.name)
except ValueError as exc:
raise HTTPException(422, str(exc)) from exc
queue.enqueue("pull")
return {"source": _one_source(store, sub.id), "found": found}