后台:修复维护问题

This commit is contained in:
luying
2022-01-14 17:11:56 +08:00
parent 211ee39645
commit fce004c079
3 changed files with 67 additions and 4 deletions

View File

@@ -66,8 +66,13 @@ export class GmHandler {
if(!id || !isNumber(startTime) || !isNumber(endTime)) return resResult(STATUS.WRONG_PARMS);
if(endTime < nowSeconds()) return resResult(STATUS.WRONG_PARMS, '结束时间不能比现在早');
const uid = session.get('uid');
let server = await ServerlistModel.findByServerId(id);
if(server && server.maintenance) {
await pinus.app.rpc.systimer.systimerRemote.stopMaintenance.broadcast(server.maintenance.batchCode, [server.id]);
}
let newMaintenance: Maintenance = { batchCode: genCode(10), startTime, endTime, hasNotify, isOpen: true }
let server = await ServerlistModel.updateByServerId(id, { maintenance: newMaintenance });
server = await ServerlistModel.updateByServerId(id, { maintenance: newMaintenance });
await pinus.app.rpc.systimer.systimerRemote.initMaintenance.broadcast([server]);
return resResult(STATUS.SUCCESS,);
@@ -81,7 +86,24 @@ export class GmHandler {
const uid = session.get('uid');
let newMaintenance: Maintenance = { batchCode: genCode(10), startTime, endTime, hasNotify, isOpen: true }
let servers = await ServerlistModel.findByEnv(this.app.get('env'));
await ServerlistModel.updateByServerIds(servers.map(server => server.id), { maintenance: newMaintenance });
let serverIdsOfBatchCode = new Map<string, number[]>();
let serverIds: number[] = [];
for(let server of servers) {
if(server.maintenance) {
let { batchCode } = server.maintenance;
if(!serverIdsOfBatchCode.has(batchCode)) {
serverIdsOfBatchCode.set(batchCode, []);
}
serverIdsOfBatchCode.get(batchCode).push(server.id);
}
serverIds.push(server.id);
}
for(let [ batchCode, serverIds ] of serverIdsOfBatchCode) {
await pinus.app.rpc.systimer.systimerRemote.stopMaintenance.broadcast(batchCode, serverIds);
}
await ServerlistModel.updateByServerIds(serverIds, { maintenance: newMaintenance });
servers = await ServerlistModel.findByEnv(this.app.get('env'));
await pinus.app.rpc.systimer.systimerRemote.initMaintenance.broadcast(servers);
return resResult(STATUS.SUCCESS,);
@@ -104,6 +126,33 @@ export class GmHandler {
return resResult(STATUS.SUCCESS,);
}
// 大区一起结束维护
async stopRegionMaintenance(msg: {}, session: BackendSession) {
const { } = msg;
const uid = session.get('uid');
let servers = await ServerlistModel.findByEnv(this.app.get('env'));
let serverIdsOfBatchCode = new Map<string, number[]>();
let serverIds: number[] = [];
for(let server of servers) {
if(server.maintenance) {
let { batchCode } = server.maintenance;
if(!serverIdsOfBatchCode.has(batchCode)) {
serverIdsOfBatchCode.set(batchCode, []);
}
serverIdsOfBatchCode.get(batchCode).push(server.id);
serverIds.push(server.id);
}
}
for(let [ batchCode, serverIds ] of serverIdsOfBatchCode) {
await pinus.app.rpc.systimer.systimerRemote.stopMaintenance.broadcast(batchCode, serverIds);
}
// 更新serverlist上的status
await ServerlistModel.updateByServerIds(serverIds, { 'maintenance.isOpen': false } as ServerlistUpdate);
return resResult(STATUS.SUCCESS,);
}
async sendMarquee(msg: { code: string }, session: BackendSession) {
const { code } = msg;
let marquee = await MarqueeModel.findByCode(code);

View File

@@ -444,8 +444,8 @@ async function setMaintenance(batchCode: string) {
let now = nowSeconds();
// 发送消息
if(maintenance.hasNotify && now < maintenance.startTime) {
if(now > maintenance.startTime - 5 * 60) {
if(maintenance.hasNotify && now < maintenance.startTime) { // 提前5分钟发通知
if(now > maintenance.startTime - 5 * 60) {
maintenanceNotifySchedule(batchCode);
} else {
if(scheduledJobs[`maintenNotify${batchCode}`]) scheduledJobs[`maintenNotify${batchCode}`].cancel();

View File

@@ -754,5 +754,19 @@
"name": "获取玩家日志列表",
"module": "log",
"type": "find"
},
{
"id": 109,
"api": "gm.gmServerHandler.stopRegionMaintenance",
"name": "结束大区维护",
"module": "server",
"type": "update"
},
{
"id": 110,
"api": "gm.gmHandler.taflus",
"name": "数数上报",
"module": "server",
"type": "update"
}
]