- 执行队列:多任务串行排队,可单独取消,超时自动放弃,异常退出后标记已中断 - 流程编排:画布多场景依赖图,内置确保登录/等待/通知/人工确认节点 - 流程定时:场景与流程统一配置定时(每天/工作日/每周/每月/每隔N小时) - 流程版本历史:自动留档 20 版,画布一键回滚且回滚可撤销 - 流程配置云备份:随定时任务备份到中心机,换机自动恢复 - 总览页/场景库布局调整,通知浮窗右下角堆叠显示
77 lines
2.4 KiB
JavaScript
77 lines
2.4 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 = 120;
|
|
|
|
// 单次运行内存中累积的日志上限(结束后由 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) {
|
|
// 从旧到新找第一条已结束的记录淘汰;全部活跃则不动(宁可短暂超限,也不丢运行中的记录)
|
|
for (const [id, rec] of RUNS) {
|
|
if (rec && (rec.status === "running" || rec.status === "queued")) continue;
|
|
RUNS.delete(id);
|
|
break;
|
|
}
|
|
}
|
|
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,
|
|
};
|