Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion bundlebees_plugin/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from typing import Any, Callable, Mapping

from . import beat_reconciliation
from . import board_plan_orphans
from . import board_stock
from .security import scrub

Expand All @@ -42,6 +43,8 @@
DUTY_MERGE = "merge_stream"
#: Flag-gated: ready-column stocking is an observation, never an action.
DUTY_STOCK = "stock_ready_column"
#: Plan/board drift: actionable cards with no slice, reported or folded.
DUTY_PLAN_ORPHANS = "board_plan_orphans"

_MAX_TEXT = 300

Expand Down Expand Up @@ -81,6 +84,8 @@ def beat(
merge_stream: Callable[[], Any] | None = None,
processor: Any = None,
branch_of: Callable[[Mapping[str, Any]], Any] | None = None,
plan_path: Any = None,
board_reader: Callable[[], Any] | None = None,
now: Any = None,
wait_s: float = 0.0,
) -> dict[str, Any]:
Expand Down Expand Up @@ -117,6 +122,26 @@ def beat(
if isinstance(outcome, Mapping)
else {"status": "ok", "result": _clip(scrub(str(outcome)))}
)
if plan_path is not None:
try:
plan_result = board_plan_orphans.check(
Path(plan_path), board_reader=board_reader, fold=True
)
except Exception as exc: # noqa: BLE001 - the beat outlives its duties
duties[DUTY_PLAN_ORPHANS] = {
"status": "error",
"reason": board_plan_orphans.REASON_PLAN_INVALID,
"reported": [],
"folded": [],
"error": _clip(scrub(f"{type(exc).__name__}: {exc}")),
}
else:
duties[DUTY_PLAN_ORPHANS] = {
"status": "ok" if plan_result.get("ok") else "error",
"reason": plan_result.get("reason"),
"reported": list(plan_result.get("reported") or []),
"folded": list(plan_result.get("folded") or []),
}
# Flag-gated and observation-only: with BUNDLEBEES_BOARD_STOCK unset the
# duty does not exist, so the report and the filesystem are unchanged.
if board_stock.enabled():
Expand Down Expand Up @@ -166,4 +191,12 @@ def scout_tick(
)


__all__ = ["DUTY_MERGE", "DUTY_STOCK", "DUTY_SWEEP", "SCHEMA", "beat", "scout_tick"]
__all__ = [
"DUTY_MERGE",
"DUTY_PLAN_ORPHANS",
"DUTY_STOCK",
"DUTY_SWEEP",
"SCHEMA",
"beat",
"scout_tick",
]
Loading