feat: background remote agent updates survive SAC navigation (0.20.19)

This commit is contained in:
2026-06-21 11:01:26 +10:00
parent d7bbcc5337
commit 5635be1322
16 changed files with 642 additions and 161 deletions
+20 -98
View File
@@ -91,7 +91,7 @@
{{ runningAgentFallback ? "Обновление…" : "Обновить через WinRM" }}
</button>
</div>
<p v-if="agentControlMessage && !actionLog.open" :class="agentControlOk ? 'success' : 'error'">{{ agentControlMessage }}</p>
<p v-if="agentControlMessage && !hostRemoteActionLog.open" :class="agentControlOk ? 'success' : 'error'">{{ agentControlMessage }}</p>
</div>
<div v-if="isLinuxHost" class="host-actions">
<div class="host-actions-row">
@@ -135,7 +135,7 @@
{{ runningAgentFallback ? "Fallback…" : "Fallback SSH" }}
</button>
</div>
<p v-if="agentControlMessage && !actionLog.open" :class="agentControlOk ? 'success' : 'error'">{{ agentControlMessage }}</p>
<p v-if="agentControlMessage && !hostRemoteActionLog.open" :class="agentControlOk ? 'success' : 'error'">{{ agentControlMessage }}</p>
<div v-if="showSshTestFeedback && (sshTestMessage || sshTestOutput)" class="host-action-feedback">
<p :class="sshTestOk ? 'success' : 'error'">{{ sshTestMessage }}</p>
<pre v-if="sshTestOutput" class="host-ssh-output">{{ sshTestOutput }}</pre>
@@ -272,38 +272,28 @@
</div>
</template>
</template>
<HostActionLogModal
:open="actionLog.open"
:title="actionLog.title"
:loading="actionLog.loading"
:ok="actionLog.ok"
:message="actionLog.message"
:output="actionLog.output"
@close="closeActionLog"
/>
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted, reactive, ref, watch } from "vue";
import { useRoute } from "vue-router";
import { useSacLiveEventStream } from "../composables/useSacLiveEventStream";
import {
hostRemoteActionLog,
runHostRemoteAction,
} from "../composables/useHostRemoteAction";
import {
apiFetch,
fetchHost,
fetchRecentEvents,
testHostWinRm,
testHostSsh,
updateHostAgentViaSsh,
requestHostAgentUpdate,
runHostAgentUpdateFallback,
patchHostAgentConfig,
type EventListResponse,
type HostDetail,
type HostSshActionResult,
} from "../api";
import { emitHostPatch } from "../utils/hostPatchBus";
import HostActionLogModal from "../components/HostActionLogModal.vue";
const HOST_ACTION_FEEDBACK_MS = 30_000;
@@ -328,14 +318,6 @@ const showSshTestFeedback = ref(false);
const sshTestMessage = ref("");
const sshTestOk = ref(false);
const sshTestOutput = ref("");
const actionLog = reactive({
open: false,
title: "",
loading: false,
ok: null as boolean | null,
message: "",
output: "",
});
const requestingAgentUpdate = ref(false);
const runningAgentFallback = ref(false);
const agentControlMessage = ref("");
@@ -609,59 +591,6 @@ function formatSshOutput(result: { stdout: string | null; stderr: string | null;
return parts.join("\n\n");
}
function openActionLog(title: string) {
actionLog.open = true;
actionLog.title = title;
actionLog.loading = true;
actionLog.ok = null;
actionLog.message = "Подключение к хосту и выполнение команды…";
actionLog.output = "";
}
function finishActionLog(result: { ok: boolean; message: string; output?: string }) {
actionLog.loading = false;
actionLog.ok = result.ok;
actionLog.message = result.message;
actionLog.output = result.output ?? "";
}
function closeActionLog() {
if (actionLog.loading) return;
actionLog.open = false;
}
async function runRemoteHostAction(
title: string,
request: () => Promise<HostSshActionResult>,
options: { refreshHost?: boolean; applyProductVersion?: boolean } = {},
) {
openActionLog(title);
try {
const result = await request();
finishActionLog({
ok: result.ok,
message: result.message,
output: formatSshOutput(result),
});
if (result.ok && result.product_version && host.value && options.applyProductVersion !== false) {
host.value = { ...host.value, product_version: result.product_version };
emitHostPatch(host.value);
} else if (host.value && result.ssh_admin_ok != null) {
host.value = { ...host.value, ssh_admin_ok: result.ssh_admin_ok };
}
if (options.refreshHost) {
await loadHost({ preserveActionLog: true });
}
return result;
} catch (e) {
finishActionLog({
ok: false,
message: e instanceof Error ? e.message : "Ошибка выполнения",
});
return null;
}
}
function applyHostDetail(detail: HostDetail) {
host.value = detail;
syncConfigFormFromHost(detail);
@@ -691,14 +620,13 @@ async function runAgentFallback() {
agentControlMessage.value = "";
const title = isWindowsHost.value ? "Обновление через WinRM" : "Fallback SSH (ssh-monitor)";
try {
const result = await runRemoteHostAction(
title,
() => runHostAgentUpdateFallback(hostId.value),
{ refreshHost: true },
);
if (result) {
agentControlOk.value = result.ok;
agentControlMessage.value = result.message;
const job = await runHostRemoteAction(hostId.value, title, "fallback");
if (job) {
agentControlOk.value = job.ok ?? false;
agentControlMessage.value = job.message || "";
if (job.ok) {
await loadHost();
}
}
} finally {
runningAgentFallback.value = false;
@@ -732,7 +660,7 @@ async function saveAgentConfig() {
}
}
async function loadHost(options: { preserveActionLog?: boolean } = {}) {
async function loadHost() {
loading.value = true;
error.value = "";
winRmTestMessage.value = "";
@@ -743,9 +671,6 @@ async function loadHost(options: { preserveActionLog?: boolean } = {}) {
showSshTestFeedback.value = false;
sshTestMessage.value = "";
sshTestOutput.value = "";
if (!options.preserveActionLog) {
closeActionLog();
}
try {
const detail = await fetchHost(hostId.value);
applyHostDetail(detail);
@@ -762,18 +687,15 @@ async function loadHost(options: { preserveActionLog?: boolean } = {}) {
async function runAgentUpdate() {
updatingAgent.value = true;
try {
const result = await runRemoteHostAction(
const job = await runHostRemoteAction(
hostId.value,
"Обновление ssh-monitor (SSH)",
() => updateHostAgentViaSsh(hostId.value),
{ refreshHost: false },
"ssh-update",
);
if (result?.ok) {
if (job?.ok) {
const detail = await fetchHost(hostId.value);
if (result.product_version) {
detail.product_version = result.product_version;
}
if (result.ssh_admin_ok != null) {
detail.ssh_admin_ok = result.ssh_admin_ok;
if (job.product_version) {
detail.product_version = job.product_version;
}
applyHostDetail(detail);
}