feat: add JD01 YAML-first deployment support
This commit is contained in:
@@ -292,28 +292,48 @@ export function runNodeHostScriptAsync(spec: HwlabRuntimeLaneSpec, script: strin
|
||||
return commandResultFromAsync(spec, payload, statusPath, false);
|
||||
}
|
||||
}
|
||||
const kill = runNodeHostScript(spec, [
|
||||
const pending = runNodeHostScript(spec, [
|
||||
"set +e",
|
||||
`status_path=${shellQuote(statusPath)}`,
|
||||
"pid=$(python3 - \"$status_path\" <<'PY' 2>/dev/null",
|
||||
"import json, sys",
|
||||
"try: print(json.load(open(sys.argv[1])).get('pid') or '')",
|
||||
"except Exception: print('')",
|
||||
`stdout_path=${shellQuote(stdoutPath)}`,
|
||||
`stderr_path=${shellQuote(stderrPath)}`,
|
||||
`timeout_seconds=${shellQuote(String(timeoutSeconds))}`,
|
||||
"python3 - \"$status_path\" \"$stdout_path\" \"$stderr_path\" \"$timeout_seconds\" <<'PY'",
|
||||
"import datetime, json, pathlib, subprocess, sys",
|
||||
"status_path, stdout_path, stderr_path, timeout_seconds = sys.argv[1:5]",
|
||||
"try:",
|
||||
" payload = json.load(open(status_path))",
|
||||
"except Exception:",
|
||||
" payload = {'state': 'missing', 'ok': False, 'exitCode': 127}",
|
||||
"def tail(path):",
|
||||
" try:",
|
||||
" return pathlib.Path(path).read_text(errors='replace')[-12000:]",
|
||||
" except FileNotFoundError:",
|
||||
" return ''",
|
||||
"pid = payload.get('pid')",
|
||||
"pid_alive = None",
|
||||
"if isinstance(pid, int) and pid > 0:",
|
||||
" pid_alive = subprocess.run(['kill', '-0', str(pid)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0",
|
||||
"payload['stdout'] = tail(stdout_path)",
|
||||
"stderr = tail(stderr_path)",
|
||||
"pending_note = f\"remote async command still pending after {timeout_seconds}s; statusPath={status_path}; pidAlive={pid_alive}\"",
|
||||
"payload['stderr'] = '\\n'.join([item for item in [pending_note, stderr] if item])",
|
||||
"payload['timedOutAt'] = datetime.datetime.utcnow().isoformat() + 'Z'",
|
||||
"payload['pidAlive'] = pid_alive",
|
||||
"json.dump(payload, sys.stdout, indent=2)",
|
||||
"PY",
|
||||
")",
|
||||
"if [ -n \"$pid\" ]; then kill \"$pid\" 2>/dev/null || true; fi",
|
||||
"cat \"$status_path\" 2>/dev/null || true",
|
||||
].join("\n"), 55);
|
||||
payload = parseJsonObject(pending.stdout.trim());
|
||||
return {
|
||||
command: [transPath(), spec.nodeRoute, "sh", "--", "<remote async script>"],
|
||||
cwd: repoRoot,
|
||||
exitCode: 124,
|
||||
stdout: typeof payload.stdout === "string" ? payload.stdout : "",
|
||||
stdout: typeof payload.stdout === "string" ? payload.stdout : pending.stdout,
|
||||
stderr: [
|
||||
`remote async command timed out after ${timeoutSeconds}s; statusPath=${statusPath}`,
|
||||
`remote async command pending after ${timeoutSeconds}s; statusPath=${statusPath}`,
|
||||
typeof payload.stderr === "string" ? payload.stderr : "",
|
||||
lastStatus?.stderr.trim() ?? "",
|
||||
kill.stderr.trim(),
|
||||
pending.stderr.trim(),
|
||||
].filter(Boolean).join("\n"),
|
||||
signal: null,
|
||||
timedOut: true,
|
||||
|
||||
Reference in New Issue
Block a user