j
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone
|
||||
@@ -199,27 +200,40 @@ def _render_worker_list(db, status_filter: str | None, limit: int) -> int:
|
||||
date_str = _extract_date(started)
|
||||
start_time = _format_event_timestamp(started)
|
||||
end_time = _format_event_timestamp(ended)
|
||||
worker_id = str(worker.get("worker_id") or worker.get("id") or "unknown")
|
||||
status = str(worker.get("status") or "unknown")
|
||||
result_state = str(worker.get("result") or "")
|
||||
status_label = status
|
||||
if result_state and result_state.lower() not in {"", status.lower()}:
|
||||
status_label = f"{status_label} ({result_state})"
|
||||
pipe_display = _summarize_pipe(worker.get("pipe"))
|
||||
error_message = _normalize_text(worker.get("error_message"))
|
||||
description = _normalize_text(worker.get("description"))
|
||||
|
||||
columns = [
|
||||
("ID", worker_id[:8]),
|
||||
("Status", status_label),
|
||||
("Pipe", pipe_display),
|
||||
("Date", date_str),
|
||||
("Start", start_time),
|
||||
("End", end_time),
|
||||
]
|
||||
if error_message:
|
||||
columns.append(("Error", error_message[:140]))
|
||||
if description and description != error_message:
|
||||
columns.append(("Details", description[:200]))
|
||||
|
||||
item = {
|
||||
"columns": [
|
||||
("Status",
|
||||
worker.get("status",
|
||||
"")),
|
||||
("Pipe",
|
||||
_summarize_pipe(worker.get("pipe"))),
|
||||
("Date",
|
||||
date_str),
|
||||
("Start Time",
|
||||
start_time),
|
||||
("End Time",
|
||||
end_time),
|
||||
],
|
||||
"__worker_metadata":
|
||||
worker,
|
||||
"_selection_args": ["-id",
|
||||
worker.get("worker_id")],
|
||||
"columns": columns,
|
||||
"__worker_metadata": worker,
|
||||
"_selection_args": ["-id", worker.get("worker_id")],
|
||||
}
|
||||
ctx.emit(item)
|
||||
log(
|
||||
f"Worker {worker_id[:8]} status={status_label} pipe={pipe_display} "
|
||||
f"error={error_message or 'none'}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
@@ -311,11 +325,25 @@ def _emit_worker_detail(worker: Dict[str, Any], events: List[Dict[str, Any]]) ->
|
||||
# Events are already always derived from stdout for now.
|
||||
|
||||
|
||||
def _summarize_pipe(pipe_value: Any, limit: int = 60) -> str:
|
||||
text = str(pipe_value or "").strip()
|
||||
def _summarize_pipe(pipe_value: Any, limit: int = 200) -> str:
|
||||
text = _normalize_text(pipe_value)
|
||||
if not text:
|
||||
return "(none)"
|
||||
return text if len(text) <= limit else text[:limit - 3] + "..."
|
||||
|
||||
stage_count = text.count("|") + 1 if text else 0
|
||||
display = text
|
||||
if len(display) > limit:
|
||||
trimmed = display[:max(limit - 3, 0)].rstrip()
|
||||
if not trimmed:
|
||||
trimmed = display[:limit]
|
||||
display = f"{trimmed}..."
|
||||
if stage_count > 1:
|
||||
suffix = f" ({stage_count} stages)"
|
||||
if not display.endswith("..."):
|
||||
display = f"{display}{suffix}"
|
||||
else:
|
||||
display = f"{display}{suffix}"
|
||||
return display
|
||||
|
||||
|
||||
def _format_event_timestamp(raw_timestamp: Any) -> str:
|
||||
@@ -378,3 +406,24 @@ def _extract_date(raw_timestamp: Any) -> str:
|
||||
except Exception:
|
||||
pass
|
||||
return date_part
|
||||
|
||||
|
||||
def _normalize_text(value: Any) -> str:
|
||||
text = str(value or "").strip()
|
||||
if not text:
|
||||
return ""
|
||||
# collapse whitespace to keep table columns aligned
|
||||
normalized = re.sub(r"\s+", " ", text)
|
||||
return normalized
|
||||
|
||||
|
||||
def _truncate_text(value: str, limit: int) -> str:
|
||||
if limit <= 0:
|
||||
return ""
|
||||
if len(value) <= limit:
|
||||
return value
|
||||
cutoff = max(limit - 3, 0)
|
||||
trimmed = value[:cutoff].rstrip()
|
||||
if not trimmed:
|
||||
return value[:limit]
|
||||
return f"{trimmed}..."
|
||||
|
||||
Reference in New Issue
Block a user