fix: show host action log modal immediately on SSH/WinRM update (0.20.9)

Open progress dialog when agent update starts so long-running remote scripts do not look frozen.
This commit is contained in:
2026-06-20 19:34:12 +10:00
parent ec5ec62240
commit 2c2f78eba9
4 changed files with 206 additions and 36 deletions
+94 -34
View File
@@ -91,7 +91,7 @@
{{ runningAgentFallback ? "Обновление…" : "Обновить через WinRM" }}
</button>
</div>
<p v-if="agentControlMessage" :class="agentControlOk ? 'success' : 'error'">{{ agentControlMessage }}</p>
<p v-if="agentControlMessage && !actionLog.open" :class="agentControlOk ? 'success' : 'error'">{{ agentControlMessage }}</p>
</div>
<div v-if="isLinuxHost" class="host-actions">
<div class="host-actions-row">
@@ -135,15 +135,11 @@
{{ runningAgentFallback ? "Fallback…" : "Fallback SSH" }}
</button>
</div>
<p v-if="agentControlMessage" :class="agentControlOk ? 'success' : 'error'">{{ agentControlMessage }}</p>
<p v-if="agentControlMessage && !actionLog.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>
</div>
<div v-if="agentUpdateMessage || agentUpdateOutput" class="host-action-feedback">
<p :class="agentUpdateOk ? 'success' : 'error'">{{ agentUpdateMessage }}</p>
<pre v-if="agentUpdateOutput" class="host-ssh-output">{{ agentUpdateOutput }}</pre>
</div>
</div>
</div>
@@ -276,6 +272,16 @@
</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">
@@ -294,8 +300,10 @@ import {
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;
@@ -320,9 +328,14 @@ const showSshTestFeedback = ref(false);
const sshTestMessage = ref("");
const sshTestOk = ref(false);
const sshTestOutput = ref("");
const agentUpdateMessage = ref("");
const agentUpdateOk = ref(false);
const agentUpdateOutput = 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("");
@@ -596,6 +609,59 @@ 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);
@@ -623,18 +689,17 @@ async function runRequestAgentUpdate() {
async function runAgentFallback() {
runningAgentFallback.value = true;
agentControlMessage.value = "";
const title = isWindowsHost.value ? "Обновление через WinRM" : "Fallback SSH (ssh-monitor)";
try {
const result = await runHostAgentUpdateFallback(hostId.value);
agentControlOk.value = result.ok;
agentControlMessage.value = result.message;
if (result.ok && result.product_version && host.value) {
host.value = { ...host.value, product_version: result.product_version };
emitHostPatch(host.value);
const result = await runRemoteHostAction(
title,
() => runHostAgentUpdateFallback(hostId.value),
{ refreshHost: true },
);
if (result) {
agentControlOk.value = result.ok;
agentControlMessage.value = result.message;
}
await loadHost();
} catch (e) {
agentControlOk.value = false;
agentControlMessage.value = e instanceof Error ? e.message : "Ошибка fallback-обновления";
} finally {
runningAgentFallback.value = false;
}
@@ -667,7 +732,7 @@ async function saveAgentConfig() {
}
}
async function loadHost() {
async function loadHost(options: { preserveActionLog?: boolean } = {}) {
loading.value = true;
error.value = "";
winRmTestMessage.value = "";
@@ -678,8 +743,9 @@ async function loadHost() {
showSshTestFeedback.value = false;
sshTestMessage.value = "";
sshTestOutput.value = "";
agentUpdateMessage.value = "";
agentUpdateOutput.value = "";
if (!options.preserveActionLog) {
closeActionLog();
}
try {
const detail = await fetchHost(hostId.value);
applyHostDetail(detail);
@@ -695,14 +761,13 @@ async function loadHost() {
async function runAgentUpdate() {
updatingAgent.value = true;
agentUpdateMessage.value = "";
agentUpdateOutput.value = "";
try {
const result = await updateHostAgentViaSsh(hostId.value);
agentUpdateOk.value = result.ok;
agentUpdateMessage.value = result.message;
agentUpdateOutput.value = formatSshOutput(result);
if (result.ok) {
const result = await runRemoteHostAction(
"Обновление ssh-monitor (SSH)",
() => updateHostAgentViaSsh(hostId.value),
{ refreshHost: false },
);
if (result?.ok) {
const detail = await fetchHost(hostId.value);
if (result.product_version) {
detail.product_version = result.product_version;
@@ -711,12 +776,7 @@ async function runAgentUpdate() {
detail.ssh_admin_ok = result.ssh_admin_ok;
}
applyHostDetail(detail);
} else if (host.value && result.ssh_admin_ok != null) {
host.value = { ...host.value, ssh_admin_ok: result.ssh_admin_ok };
}
} catch (e) {
agentUpdateOk.value = false;
agentUpdateMessage.value = e instanceof Error ? e.message : "Ошибка обновления агента";
} finally {
updatingAgent.value = false;
}