refactor: organize source web and tests by business module
This commit is contained in:
1 parent
9854d2d5c2
commit
2aed328774
113 files changed
+189
-183
No files matched your search
@@ -1,34 +0,0 @@
|
||||
const crypto=require('node:crypto');
|
||||
class BpmCustodian {
|
||||
constructor({workspace,manager,intervalMs=5*60*1000}){
|
||||
this.workspace=workspace;this.manager=manager;this.intervalMs=intervalMs;this.stopped=false;this.running=null;
|
||||
this.principal={user:{id:'bpm-custodian',username:'系统托管',role:'admin'},sessionId:'custodian:'+crypto.randomBytes(24).toString('hex')};
|
||||
}
|
||||
start(){if(this.timer || this.stopped)return;this.timer=setInterval(()=>{this.tick().catch(()=>{});},this.intervalMs);this.timer.unref?.();this.tick().catch(()=>{});}
|
||||
tick(){
|
||||
if(this.stopped || this.running)return Promise.resolve();
|
||||
this.running=this.checkAll().finally(()=>{this.running=null;});return this.running;
|
||||
}
|
||||
async checkAll(){
|
||||
const connections=this.workspace.snapshot().connections;
|
||||
for(const candidate of connections){
|
||||
if(this.stopped)break;
|
||||
if(candidate.status==='disabled')continue;
|
||||
try{
|
||||
const connection=this.workspace.getConnection(candidate.id);
|
||||
if(connection.status==='disabled')continue;
|
||||
const account=await this.manager.account(connection,this.principal);
|
||||
if(!account.configured && !connection.lastConnectedAt && !['connected','unchecked','login_required'].includes(connection.status))continue;
|
||||
const result=await this.manager.ensure(connection,this.principal);
|
||||
// The connection can be disabled while its remote check is in flight.
|
||||
if(this.workspace.getConnection(connection.id).status!=='disabled')this.workspace.updateConnectionSession(connection.id,result,this.principal.user);
|
||||
}catch(cause){
|
||||
// Interactive leases and transient browser failures are retried on the next cycle.
|
||||
// The manager returns checked upstream failures as structured results.
|
||||
if(![403,404,409,429].includes(cause.status))this.lastErrorAt=new Date().toISOString();
|
||||
}
|
||||
}
|
||||
}
|
||||
async stop(){this.stopped=true;clearInterval(this.timer);this.timer=null;await this.running;}
|
||||
}
|
||||
module.exports={BpmCustodian};
|
||||
Reference in new issue
Block a user