diff --git a/src/app/application.cjs b/src/app/application.cjs index ac636e3..847ba35 100644 --- a/src/app/application.cjs +++ b/src/app/application.cjs @@ -113,6 +113,7 @@ async function main(options = {}) { health.start(); orderExecution.start(); orderDispatcher.start(); + orderExecution.warmup(custodian.principal).then(result=>{if(!result?.started)console.warn('运行能力预热未完成:'+(result?.error||'未知原因'));}).catch(error=>console.warn('运行能力预热失败:'+error.message)); if(!options.quiet){ console.log('订单通知中心已启动。\nWeb 工作台支持业务日历、异常待办与转交、BPM 连接管理。\n在 Chrome 订单页仍可点击扩展中的“导出当前订单”。'); console.log(`首次使用:Chrome 扩展管理 → 开发者模式 → 加载已解压的扩展程序\n选择目录:${installedExtension}\n输出目录:${outputDir}\n本地服务:http://127.0.0.1:${port}`); diff --git a/src/modules/order-execution/coordinator.cjs b/src/modules/order-execution/coordinator.cjs index cda0498..54c4334 100644 --- a/src/modules/order-execution/coordinator.cjs +++ b/src/modules/order-execution/coordinator.cjs @@ -129,7 +129,20 @@ class OrderExecutionCoordinator{ listFieldSamples(input,principal){return require('./field-samples.cjs').listFieldSamples(this,input,principal);} captureFieldSample(input,principal){return require('./field-samples.cjs').captureFieldSample(this,input,principal);} connection(id,principal){const c=this.workspace.getConnection(id);if(!principal?.sessionId||!['admin','operator'].includes(principal?.user?.role)||(principal.user.role!=='admin'&&c.owner!==principal.user.username))fail('仅连接负责人或管理员可以扫描或重试。',403);if(c.status==='disabled')fail('连接已停用。',409);return c;} - async refreshCapabilities(rule){ + async warmup(principal){ + // Restart clears in-memory runtime capabilities; re-prove them before the next send window. + if(this.stopped)return {started:false,error:'服务正在关闭'}; + let rule=null; + try{rule=this.store.all('rules').map(record=>this.store.executionRule(record)).find(item=>item?.status==='enabled'&&item.archiveDirectory)||null;}catch{} + let connection=null; + try{connection=this.workspace.snapshot().connections.find(item=>item.status==='connected')||null;}catch{} + if(connection&&typeof this.provider.scan==='function'){ + try{await this.provider.scan(connection,principal);}catch(error){this.blockers.push('启动预热待办扫描失败:'+error.message);} + } + if(!rule)return {started:false,error:'没有已启用且配置归档目录的规则'}; + try{await this.refreshCapabilities(rule);}catch(error){return {started:false,error:error.message};} + return {started:true,ruleId:rule.id,connectionId:connection?.id||null}; +}async refreshCapabilities(rule){ let p={},a={};this.blockers=[]; try{p=await this.provider.capabilities();}catch(error){this.blockers.push('待办提供器探测失败:'+error.message);} try{a=rule&&this.archive.probe?await this.archive.probe(rule):await this.archive.capabilities();}catch(error){this.blockers.push('归档运行条件探测失败:'+error.message);}