rpc优化:所有remote加上try catch
This commit is contained in:
@@ -6,6 +6,7 @@ import { _getActivitiesByType, _getActivityById, _getActivities } from '../../..
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { taflush } from '../../../services/sdkService';
|
||||
import { ActivityInRemote } from '../../../domain/activityField/activityField';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -29,33 +30,41 @@ export class ActivityRemote {
|
||||
* 重载json资源
|
||||
*/
|
||||
public async reloadResources() {
|
||||
reloadResources();
|
||||
try {
|
||||
reloadResources();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async loadActivities() {
|
||||
let servers = await ServerlistModel.findByEnv(this.app.get('env'));
|
||||
for(let { id: serverId, activityGroupId } of servers) {
|
||||
for(let groupId of activityGroupId) {
|
||||
if(!this.groupToServer.has(groupId)) {
|
||||
this.groupToServer.set(groupId, []);
|
||||
try {
|
||||
let servers = await ServerlistModel.findByEnv(this.app.get('env'));
|
||||
for(let { id: serverId, activityGroupId } of servers) {
|
||||
for(let groupId of activityGroupId) {
|
||||
if(!this.groupToServer.has(groupId)) {
|
||||
this.groupToServer.set(groupId, []);
|
||||
}
|
||||
this.groupToServer.get(groupId).push(serverId);
|
||||
}
|
||||
this.groupToServer.get(groupId).push(serverId);
|
||||
}
|
||||
|
||||
let activities = await ActivityModel.findOpenAndComingActivityes();
|
||||
let activityIds: number[] = [];
|
||||
for(let activity of activities) {
|
||||
this.activities.set(activity.activityId, new ActivityInRemote(activity));
|
||||
activityIds.push(activity.activityId);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
// console.log('****** loadActivities')
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
|
||||
let activities = await ActivityModel.findOpenAndComingActivityes();
|
||||
let activityIds: number[] = [];
|
||||
for(let activity of activities) {
|
||||
this.activities.set(activity.activityId, new ActivityInRemote(activity));
|
||||
activityIds.push(activity.activityId);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
// console.log('****** loadActivities')
|
||||
}
|
||||
|
||||
private setActivityTypeAndServer() {
|
||||
@@ -87,76 +96,120 @@ export class ActivityRemote {
|
||||
}
|
||||
|
||||
public async updateActivities(activities: ActivityInRemote[]) {
|
||||
// console.log('******* activities', activities)
|
||||
let activityIds: number[] = [];
|
||||
for(let activity of activities) {
|
||||
this.activities.set(activity.activityId, activity);
|
||||
activityIds.push(activity.activityId);
|
||||
try {
|
||||
// console.log('******* activities', activities)
|
||||
let activityIds: number[] = [];
|
||||
for(let activity of activities) {
|
||||
this.activities.set(activity.activityId, activity);
|
||||
activityIds.push(activity.activityId);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
}
|
||||
|
||||
public async deleteActivities(activityIds: number[]) {
|
||||
for(let activityId of activityIds) {
|
||||
this.activities.delete(activityId);
|
||||
try {
|
||||
for(let activityId of activityIds) {
|
||||
this.activities.delete(activityId);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
}
|
||||
|
||||
public async saveGroupToServer(groupId: number, serverIds: number[]) {
|
||||
this.groupToServer.set(groupId, serverIds);
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
try {
|
||||
this.groupToServer.set(groupId, serverIds);
|
||||
this.setActivityTypeAndServer();
|
||||
|
||||
this.app.set('activityByServer', this.activityByServer);
|
||||
this.app.set('activityByType', this.activityByType);
|
||||
this.app.set('activities', this.activities);
|
||||
this.app.set('groupToServer', this.groupToServer);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async saveActivitiesToGroup(groupId: number, activities: number[]) {
|
||||
for(let activityId of activities) {
|
||||
if(this.activities.get(activityId)) {
|
||||
this.activities.get(activityId).groupId = groupId;
|
||||
try {
|
||||
for(let activityId of activities) {
|
||||
if(this.activities.get(activityId)) {
|
||||
this.activities.get(activityId).groupId = groupId;
|
||||
}
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
this.setActivityTypeAndServer();
|
||||
}
|
||||
|
||||
public getActivityById(activityId: number) {
|
||||
return _getActivityById(activityId);
|
||||
try {
|
||||
return _getActivityById(activityId);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public getActivitiesByType(serverId: number, type: number) {
|
||||
return _getActivitiesByType(serverId, type);
|
||||
try {
|
||||
return _getActivitiesByType(serverId, type);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public getActivities() {
|
||||
return _getActivities();
|
||||
try {
|
||||
return _getActivities();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public setServerMainten(serverIds: number[], startTime: number, endTime: number) {
|
||||
setServerMainten(serverIds, startTime, endTime);
|
||||
try {
|
||||
setServerMainten(serverIds, startTime, endTime);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public stopServerMainten(serverIds: number[]) {
|
||||
stopServerMainten(serverIds);
|
||||
try {
|
||||
stopServerMainten(serverIds);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public getServerMainten(serverId: number) {
|
||||
return getServerMainten(serverId);
|
||||
try {
|
||||
return getServerMainten(serverId);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public taflush() {
|
||||
return taflush();
|
||||
try {
|
||||
return taflush();
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user