Print each chunk that asks a question and since when each parked chunk awaits its gate in do-epic --status
CI / tests (pull_request) Failing after 3m23s
CI / tests (pull_request) Failing after 3m23s
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""What `do-epic <EPIC-KEY> --status` prints: each open issue of the epic, with whether its chunk runs, asks the human, is parked on a gate, has stopped or has yet to start (docs/decisions.md → `do-epic: drives one Jira epic …`)."""
|
||||
import datetime
|
||||
import pathlib
|
||||
|
||||
from agent_cycle import tmux
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from do_epic.parked import file_of, Parked, parked_chunks
|
||||
from do_epic.scheduler import chunks, STATE
|
||||
from failure import Failure
|
||||
|
||||
|
||||
def since(folder: pathlib.Path, chunk: Parked) -> str:
|
||||
"""When the chunk parked on what its file says it awaits, to the minute in the machine's time zone: the file is written once per gate, so its time is when the gate began. Empty where the file cannot be read."""
|
||||
try:
|
||||
return datetime.datetime.fromtimestamp(file_of(folder, chunk.issue).stat().st_mtime).strftime("%Y-%m-%d %H:%M")
|
||||
except OSError:
|
||||
return ""
|
||||
|
||||
|
||||
def lines(key: str, home: pathlib.Path, issues: list[EpicIssue], run: tmux.Tmux) -> list[str] | Failure:
|
||||
"""A line per open issue of the epic called key, in the tracker's rank order: that its chunk runs or asks the human, or why it waits. It doesn't start anything and checks no limit, so the line of a chunk that has yet to start doesn't say which limit holds it back."""
|
||||
found, waits = chunks(issues)
|
||||
folder = home / STATE / key
|
||||
parked = parked_chunks(folder)
|
||||
if isinstance(parked, Failure):
|
||||
return parked
|
||||
session = tmux.session_name(tmux.EPIC, key)
|
||||
windows = tmux.listed(session, run)
|
||||
live = {window.name: window for window in windows if not window.dead}
|
||||
again = f"run `do-epic {key}` to start it again"
|
||||
reasons = {wait.issue: wait.reason for wait in waits}
|
||||
for chunk in found:
|
||||
if chunk.issue in parked:
|
||||
gate = since(folder, parked[chunk.issue])
|
||||
when = f", since {gate}" if gate else ""
|
||||
reasons[chunk.issue] = parked[chunk.issue].waits(live[chunk.issue].awaits) + when if chunk.issue in live else f"{parked[chunk.issue].waits('')}{when}, and its window stopped; {again}"
|
||||
elif chunk.issue not in live:
|
||||
reasons[chunk.issue] = f"its window stopped; {again}" if chunk.issue in {window.name for window in windows} else f"it has not started; `do-epic {key}` starts it once the epic and its repo have room"
|
||||
return [line(issue.key, reasons, live, session) for issue in issues if issue.key in reasons or issue.key in live]
|
||||
|
||||
|
||||
def line(issue: str, reasons: dict[str, str], live: dict[str, tmux.Listed], session: str) -> str:
|
||||
"""The status line of issue, whose chunk has a live window or a reason not to run."""
|
||||
if issue in reasons:
|
||||
return f"{issue} waits: {reasons[issue]}"
|
||||
return f"{issue} asks you: answer its question in the tmux window {session}:{issue}" if live[issue].asks else f"{issue} runs"
|
||||
Reference in New Issue
Block a user