- 启动链路 P1-P7 修复:预算对齐、完成事件推送、端口占用提示、前端阶段文案接管 - 静态缓存按 IS_FROZEN 区分开发/打包态,bootPhaseOwned 竞态修复 - 一键执行与参数配置统一收口到插件界面,定时任务引用 config_id - 环境包迁移到 %LOCALAPPDATA%\37duAutomation\python-env,重装零解压 - shell-updater:缓存包 sha256 校验、静默升级后自动拉起新版、自动清理旧安装包 - after-pack 钩子生成 shell.version 修复打包态版本识别 - 插件 xq0031/xq0045 迁移至 plugins/XQ0001-0100/ 号段分桶中文目录
71 lines
2.0 KiB
JavaScript
71 lines
2.0 KiB
JavaScript
// 运行时共享状态:可变全局唯一真源(对齐 Python webhost state.py)。
|
|
"use strict";
|
|
|
|
const PLATFORMS = {
|
|
hr: { id: "hr", label: "HR 系统" },
|
|
oa: { id: "oa", label: "OA 系统" },
|
|
};
|
|
|
|
// 运行会话:run_id -> {status, account, plugin_id, name, version, trigger, schedule_id, started, result, error, logs}
|
|
const RUNS = new Map();
|
|
const MAX_RUNS = 50;
|
|
|
|
// 单次运行内存中累积的日志上限(结束后由 run-history 落盘,此处只服务"正在跑"的实时展示与回放)
|
|
const MAX_RUN_LOGS = 800;
|
|
|
|
// 插件权限白名单(null = 全量;空集 = 零权限)。由登录/启动/同步决定。
|
|
let ALLOWED = null;
|
|
|
|
function setAllowed(v) {
|
|
ALLOWED = v === undefined ? null : v;
|
|
}
|
|
|
|
// 启动步骤状态(启动页/登录页展示"当前在干嘛";后台初始化失败/超时只记日志,不阻塞 UI)
|
|
let BOOT = { step: "初始化中", detail: "", done: false, at: "" };
|
|
function setBootStep(step, detail = "") {
|
|
BOOT = { step, detail, done: false, at: new Date().toISOString() };
|
|
}
|
|
function setBootDone() {
|
|
BOOT = { ...BOOT, done: true, at: new Date().toISOString() };
|
|
}
|
|
function bootStatus() {
|
|
return { ...BOOT };
|
|
}
|
|
|
|
function setRun(runId, fields) {
|
|
const run = RUNS.get(runId);
|
|
if (run) Object.assign(run, fields);
|
|
}
|
|
|
|
function registerRun(runId, record) {
|
|
if (RUNS.size >= MAX_RUNS) {
|
|
const oldest = RUNS.keys().next().value;
|
|
RUNS.delete(oldest);
|
|
}
|
|
RUNS.set(runId, record);
|
|
}
|
|
|
|
// 累积"这一次运行"的日志:日志是运行的属性,跟着运行走(不再是全局单例)
|
|
function appendRunLog(runId, entry) {
|
|
const run = RUNS.get(runId);
|
|
if (!run) return;
|
|
if (!Array.isArray(run.logs)) run.logs = [];
|
|
run.logs.push(entry);
|
|
if (run.logs.length > MAX_RUN_LOGS) run.logs.splice(0, run.logs.length - MAX_RUN_LOGS);
|
|
}
|
|
|
|
module.exports = {
|
|
PLATFORMS,
|
|
RUNS,
|
|
MAX_RUNS,
|
|
MAX_RUN_LOGS,
|
|
ALLOWED,
|
|
setAllowed,
|
|
setRun,
|
|
registerRun,
|
|
appendRunLog,
|
|
setBootStep,
|
|
setBootDone,
|
|
bootStatus,
|
|
};
|