feat: complete workflow recovery and safe administration
This commit is contained in:
1 parent
1148aa6f14
commit
69583e8c33
46 files changed
+756
-120
No files matched your search
@@ -1,7 +1,7 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
let api,esc,formatDate;
|
||||
const statuses={healthy:['上次正常','green'],error:['上次失败','red'],pending:['待检查','yellow'],disabled:['已停用','secondary'],paused:['已暂停','secondary'],running:['执行中','blue'],unknown:['状态未知','orange'],unconfigured:['未配置','secondary']};
|
||||
let api,esc,formatDate,user;
|
||||
const statuses={healthy:['上次正常','green'],error:['上次失败','red'],pending:['待检查','yellow'],disabled:['已停用','secondary'],paused:['已暂停','secondary'],running:['执行中','blue'],unknown:['状态未知','orange'],stale:['记录已过期','yellow'],healthy_stale:['成功记录已过期','yellow'],unconfigured:['未配置','secondary']};
|
||||
const guards={running:['守护正常','green'],starting:['启动中','blue'],backoff:['等待恢复','orange'],cooldown:['恢复冷却中','orange'],stale:['守护心跳过期','red'],unmanaged:['未通过守护启动','yellow'],stopped:['已停止','secondary'],stopping:['停止中','secondary']};
|
||||
const reasons={healthy:'两个服务端口心跳正常',initial_start:'首次启动',unexpected_exit:'业务进程意外退出',health_timeout:'服务持续无响应',manual_restart:'手动重启',manual_stop:'手动停止',port_conflict:'服务端口已被占用',spawn_failed:'进程启动失败',startup_failed:'启动失败'};
|
||||
const events={guard_started:'守护启动',child_exit:'业务进程退出',unresponsive:'服务持续无响应',restarting:'准备自动恢复',cooldown:'多次失败,进入冷却',manual_restart:'手动重启',guard_stopped:'守护停止',monitor_error:'守护检查异常',spawn_failed:'业务进程启动失败',autostart_installed:'启用 Windows 登录自启',autostart_removed:'移除 Windows 登录自启'};
|
||||
@@ -9,7 +9,7 @@
|
||||
function badge(status,map=statuses){const [label,color]=map[status]||['状态未知','secondary'];return `<span class="badge bg-${color}-lt">${label}</span>`;}
|
||||
async function render(container,isActive=()=>true){
|
||||
const live=()=>isActive()&&container.isConnected;let pending=false,timer;
|
||||
container.innerHTML=`<div class="card mb-3"><div class="card-body d-flex gap-3 flex-wrap align-items-center"><div class="flex-fill"><h2 class="card-title mb-1">服务守护与健康状态</h2><div class="text-secondary small">上次检查结果,非实时连通性检测</div></div><button class="btn" type="button" id="health-refresh">刷新健康状态</button></div><div class="card-footer small" id="health-refresh-state" role="status" aria-live="polite">正在读取健康状态…</div></div><div id="health-runtime" class="mb-3"></div><div id="health-groups" class="row row-cards"></div><div id="health-events" class="mt-3"></div>`;
|
||||
container.innerHTML=`<div class="card mb-3"><div class="card-body d-flex gap-3 flex-wrap align-items-center"><div class="flex-fill"><h2 class="card-title mb-1">服务守护与健康状态</h2><div class="text-secondary small">上次检查结果,非实时连通性检测</div></div><button class="btn" type="button" id="health-refresh">刷新健康状态</button></div><div class="card-footer small" id="health-refresh-state" role="status" aria-live="polite">正在读取健康状态…</div></div><div id="health-runtime" class="mb-3"></div><div id="health-groups" class="row row-cards"></div><div id="health-events" class="mt-3"></div><div id="health-maintenance" class="mt-3"></div>`;
|
||||
const button=container.querySelector('#health-refresh'),notice=container.querySelector('#health-refresh-state');
|
||||
function draw(data){
|
||||
const {runtime}=data,guard=runtime.guard;
|
||||
@@ -23,7 +23,8 @@
|
||||
catch{if(live()){const access=container.querySelector('#health-access');if(access){access.className='badge bg-red-lt ms-auto';access.textContent='连接中断';}notice.className='card-footer small text-danger';notice.textContent='暂时无法连接服务,保留上次状态;恢复后会自动更新。';}}
|
||||
finally{pending=false;if(live()){button.disabled=false;timer=setTimeout(refresh,10000);}}
|
||||
}
|
||||
if(user?.role==='admin'){const box=container.querySelector('#health-maintenance');box.innerHTML='<section class="card"><div class="card-header"><h3 class="card-title">数据容量与保留</h3><button class="btn btn-sm ms-auto" type="button" id="capacity-refresh">刷新容量</button></div><div class="card-body" id="capacity-content">正在读取…</div></section>';const load=async()=>{const b=container.querySelector('#capacity-refresh');b.disabled=true;try{const d=await api('/maintenance');if(live())container.querySelector('#capacity-content').innerHTML='<p>默认永久保留;会话归档及异常退役保留原证据。</p><p>状态数据 '+(d.state.bytes/1048576).toFixed(2)+' MiB · PDF '+d.pdf.files+' 份 / '+(d.pdf.bytes/1048576).toFixed(2)+' MiB · 导出台账 '+d.jobs.total+' 条</p><a class="btn" href="/api/jobs/export">导出 PDF 历史</a><p class="small text-secondary mt-3 mb-0">备份与恢复按停服操作指南执行;只恢复到新空目录。</p>';}catch(e){if(live())container.querySelector('#capacity-content').textContent=e.message;}finally{if(live())b.disabled=false;}};container.querySelector('#capacity-refresh').onclick=load;void load();}
|
||||
button.onclick=refresh;await refresh();
|
||||
}
|
||||
window.HealthViews={configure:options=>({api,esc,formatDate}=options),render};
|
||||
window.HealthViews={configure:options=>({api,esc,formatDate,user}=options),render};
|
||||
})();
|
||||
Reference in new issue
Block a user