api 锁修改
This commit is contained in:
parent
60d0e04e33
commit
826840455c
16
src/setWs.ts
16
src/setWs.ts
@ -28,7 +28,7 @@ export async function createWs() {
|
||||
apiTimeout: 300000,
|
||||
logLevel: G.argv.logModel as LogLevel,
|
||||
logger:mylogger
|
||||
});
|
||||
});
|
||||
setCrossWs(G.serverCross);
|
||||
await G.serverCross.autoImplementApi(resolve(__dirname, 'api_cross'), true);
|
||||
await G.serverCross.start();
|
||||
@ -139,14 +139,14 @@ function setWs(server: WsServer<ServiceType>) {
|
||||
|
||||
//处理API锁,极限情况下只锁10s,防止死锁
|
||||
//在下方postApiReturnFlow里会解锁
|
||||
if (call.conn.apiLock[call.service.name] && new Date().getTime() - call.conn.apiLock[call.service.name] < 10000) {
|
||||
if (call.conn.apiLock[call.service.name] && call.conn.apiLock[call.service.name] > new Date().getTime()) {
|
||||
call.error('', {code: -100, message: '', time: 0});
|
||||
return null;
|
||||
}
|
||||
|
||||
//API锁定
|
||||
//API锁定到什么时候
|
||||
if (!writeList.includes(call.service.name)) {
|
||||
call.conn.apiLock[call.service.name] = new Date().getTime();
|
||||
call.conn.apiLock[call.service.name] = new Date().getTime() + 10000;
|
||||
}
|
||||
//API耗时统计
|
||||
call.conn.requstApiTime[call.service.name] = new Date().getTime();
|
||||
@ -196,7 +196,13 @@ function setWs(server: WsServer<ServiceType>) {
|
||||
}
|
||||
|
||||
//API解锁
|
||||
delete node.call.conn.apiLock[node.call.service.name];
|
||||
let now = new Date().getTime();
|
||||
|
||||
if(node.return.isSucc){
|
||||
node.call.conn.apiLock[node.call.service.name] = now+200;
|
||||
}else{
|
||||
delete node.call.conn.apiLock[node.call.service.name];
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user