fix: make hwlab monitor status read-only
This commit is contained in:
@@ -3,7 +3,7 @@ import { dirname, join } from "node:path";
|
||||
import { createHash } from "node:crypto";
|
||||
import { repoRoot, rootPath, type Config } from "./config";
|
||||
import { runCommand } from "./command";
|
||||
import { startJob } from "./jobs";
|
||||
import { readJob, startJob } from "./jobs";
|
||||
|
||||
const HWLAB_REPO = "pikasTech/HWLAB";
|
||||
const G14_SOURCE_BRANCH = "G14";
|
||||
@@ -5347,6 +5347,7 @@ export function hwlabG14Help(): Record<string, unknown> {
|
||||
usage: [
|
||||
"bun scripts/cli.ts hwlab g14 monitor-prs",
|
||||
"bun scripts/cli.ts hwlab g14 monitor-prs --lane v02",
|
||||
"bun scripts/cli.ts hwlab g14 monitor-prs --lane v02 --status",
|
||||
"bun scripts/cli.ts hwlab g14 monitor-prs --once --dry-run",
|
||||
"bun scripts/cli.ts hwlab g14 monitor-prs --lane v02 --once --dry-run",
|
||||
"bun scripts/cli.ts hwlab g14 record-rollout --pr <number> [--source-commit sha]",
|
||||
@@ -5405,6 +5406,67 @@ export function hwlabG14Help(): Record<string, unknown> {
|
||||
};
|
||||
}
|
||||
|
||||
function monitorStatus(options: G14MonitorOptions): Record<string, unknown> {
|
||||
const stateDir = rootPath(".state", "hwlab-g14");
|
||||
const stateFileName = hwlabG14MonitorStateFileName(options);
|
||||
const stateFileRole = hwlabG14MonitorStateRole(options);
|
||||
const latestPath = join(stateDir, stateFileName);
|
||||
const exists = existsSync(latestPath);
|
||||
let latest: Record<string, unknown> | null = null;
|
||||
let job: Record<string, unknown> | null = null;
|
||||
let statusCommand: string | null = null;
|
||||
let degradedReason: string | null = null;
|
||||
if (exists) {
|
||||
try {
|
||||
latest = record(JSON.parse(readFileSync(latestPath, "utf8")) as unknown);
|
||||
const jobId = typeof latest.jobId === "string" ? latest.jobId : null;
|
||||
if (jobId !== null) {
|
||||
statusCommand = `bun scripts/cli.ts job status ${jobId} --tail-bytes 30000`;
|
||||
try {
|
||||
const current = readJob(jobId);
|
||||
job = {
|
||||
id: current.id,
|
||||
name: current.name,
|
||||
status: current.status,
|
||||
createdAt: current.createdAt,
|
||||
startedAt: current.startedAt,
|
||||
finishedAt: current.finishedAt,
|
||||
exitCode: current.exitCode,
|
||||
runnerPid: current.runnerPid ?? null,
|
||||
stdoutFile: current.stdoutFile,
|
||||
stderrFile: current.stderrFile,
|
||||
note: current.note,
|
||||
};
|
||||
} catch (error) {
|
||||
degradedReason = error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
degradedReason = `failed to parse ${latestPath}: ${error instanceof Error ? error.message : String(error)}`;
|
||||
}
|
||||
}
|
||||
return {
|
||||
ok: degradedReason === null,
|
||||
command: "hwlab g14 monitor-prs --status",
|
||||
lane: options.lane,
|
||||
baseBranch: monitorBaseBranch(options.lane),
|
||||
mode: "status",
|
||||
latestPath,
|
||||
stateFileName,
|
||||
stateFileRole,
|
||||
exists,
|
||||
latest,
|
||||
job,
|
||||
statusCommand,
|
||||
degradedReason,
|
||||
next: statusCommand === null ? {
|
||||
start: `bun scripts/cli.ts hwlab g14 monitor-prs --lane ${options.lane}`,
|
||||
} : {
|
||||
status: statusCommand,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function runHwlabG14Command(_config: Config, args: string[]): Promise<Record<string, unknown>> {
|
||||
if (args.length === 0 || args.includes("--help") || args.includes("-h")) return { ok: true, ...hwlabG14Help() };
|
||||
const [action] = args;
|
||||
@@ -5439,6 +5501,7 @@ export async function runHwlabG14Command(_config: Config, args: string[]): Promi
|
||||
}
|
||||
const options = parseOptions(args.slice(1));
|
||||
if (options.worker) return runMonitorWorker(options);
|
||||
if (args.includes("--status")) return monitorStatus(options);
|
||||
const command = ["bun", "scripts/cli.ts", "hwlab", "g14", "monitor-prs", "--worker", "--lane", options.lane, "--interval-seconds", String(options.intervalSeconds), "--timeout-seconds", String(options.timeoutSeconds), ...(options.once ? ["--once"] : []), ...(options.dryRun ? ["--dry-run"] : []), ...(options.maxCycles > 0 ? ["--max-cycles", String(options.maxCycles)] : [])];
|
||||
const jobName = options.lane === "v02" ? "hwlab_g14_v02_pr_monitor" : "hwlab_g14_pr_monitor";
|
||||
const jobNote = options.lane === "v02"
|
||||
|
||||
Reference in New Issue
Block a user