新增 - 计划任务路由基础

This commit is contained in:
suwings 2018-06-02 14:05:21 +08:00
parent 9e2c9690b0
commit 8125552d5d
3 changed files with 68 additions and 1 deletions

View File

@ -16,7 +16,9 @@ class MinecraftServer extends ServerProcess {
this.dataModel.name = name; //服务器名字
this.dataModel.createDate = now; //创建时间
this.dataModel.lastDate = now; //最后启动时间
this.dataModel.autoRestart = false; //是否自动重启
this.dataModel.schedule = {}; //计划任务配置项目
this.properties = undefined; //服务端配置表

View File

@ -14,7 +14,7 @@ module.exports.createScheduleJob = (id, time, callback) => {
}
//计次型任务
module.exports.createScheduleJobCount = (id, time, callback, count) => {
module.exports.createScheduleJobCount = (id, time, count, callback) => {
let lco = 0;
let mask = MCSERVER.Schedule.container[id] = schedule.scheduleJob(time, (fireDate) => {
if (lco >= count) {

View File

@ -0,0 +1,65 @@
const {
WebSocketObserver
} = require('../../model/WebSocketModel');
const permssion = require('../../helper/Permission');
const schedulejob = require('../../helper/Schedule');
const UUID = require('uuid');
const tools = require('../core/tools');
const serverModel = require('../../model/ServerModel');
let e = {
servername: "xxxxxx",
commande: "xxxxxx",
timestr: "",
count: 0
}
function CreateScheduleJob(obj) {
let id = tools.randomString(6) + "_" + new Date().getTime();
if (obj.count <= 0) {
schedulejob.createScheduleJob(id, obj.timestr, () => {
});
} else {
schedulejob.createScheduleJobCount(id, obj.timestr, obj.count, () => {
});
}
}
//列出计划任务
WebSocketObserver().listener('schedule/list', (data) => {
let username = data.WsSession.username;
let servername = data.body;
if (permssion.isCanServer(username, servername)) {
let thisServer = serverModel.ServerManager().getServer(servername);
} else {
MCSERVER.log('权限不足!');
}
});
//创建计划任务
WebSocketObserver().listener('schedule/create', (data) => {
let username = data.WsSession.username;
let obj = JSON.parse(data.body);
if (permssion.isCanServer(username, obj.servername || "")) {
CreateScheduleJob(obj);
} else {
MCSERVER.log('权限不足!');
}
});
//删除计划任务
WebSocketObserver().listener('schedule/delete', (data) => {
let username = data.WsSession.username;
let obj = JSON.parse(data.body);
if (permssion.isCanServer(username, obj.servername || "")) {
schedulejob.deleteScheduleJob(obj.id);
} else {
MCSERVER.log('权限不足2');
}
});