mirror of
https://github.com/MCSManager/MCSManager.git
synced 2024-11-21 03:12:10 +08:00
新增 - 计划任务功能
This commit is contained in:
parent
e5d8e6d9c5
commit
0293ad3c93
2
app.js
2
app.js
@ -186,6 +186,7 @@ process.on("uncaughtException", function (err) {
|
||||
const USERS_PATH = './users/';
|
||||
const SERVER_PATH = './server/';
|
||||
const SERVER_PATH_CORE = './server/server_core/';
|
||||
const SERVER_PATH_SCH = './server/schedule/';
|
||||
const CENTEN_LOG_JSON_PATH = './core/info.json';
|
||||
const PUBLIC_URL_PATH = './public/common/URL.js';
|
||||
|
||||
@ -193,6 +194,7 @@ process.on("uncaughtException", function (err) {
|
||||
if (!fs.existsSync(USERS_PATH)) fs.mkdirSync(USERS_PATH);
|
||||
if (!fs.existsSync(SERVER_PATH)) {
|
||||
fs.mkdir(SERVER_PATH, () => fs.mkdirSync(SERVER_PATH_CORE));
|
||||
fs.mkdirSync(SERVER_PATH_SCH);
|
||||
}
|
||||
|
||||
// 生成不 git 同步的文件
|
||||
|
@ -1,18 +1,41 @@
|
||||
const schedule = require("node-schedule");
|
||||
const DataModel = require('../core/DataModel');
|
||||
const fs = require('fs');
|
||||
|
||||
const PATH = 'server/_ schedule _.js';
|
||||
const DataModel = require('../core/DataModel');
|
||||
const serverModel = require('../model/ServerModel');
|
||||
|
||||
const PATH = 'server/schedule/_ schedule _.js';
|
||||
|
||||
MCSERVER.Schedule = {};
|
||||
MCSERVER.Schedule.container = {};
|
||||
MCSERVER.Schedule.dataModel = new DataModel(PATH)
|
||||
MCSERVER.Schedule.dataModel.list = [];
|
||||
|
||||
function serverExe(commande) {
|
||||
console.log("执行:" + commande)
|
||||
function serverExe(servername, commande) {
|
||||
MCSERVER.log("[ Schedule ] [", servername, "] 服务器计划执行: ", commande);
|
||||
try {
|
||||
if (commande == "__start__") {
|
||||
serverModel.startServer(servername);
|
||||
}
|
||||
if (commande == "__stop__") {
|
||||
serverModel.stopServer(servername);
|
||||
}
|
||||
if (commande == "__restart__") {
|
||||
serverModel.stopServer(servername);
|
||||
setTimeout(() => {
|
||||
serverModel.startServer(servername);
|
||||
}, 15000)
|
||||
}
|
||||
//默认执行命令
|
||||
serverModel.sendCommand(servername, commande);
|
||||
} catch (err) {
|
||||
//默认忽略定时计划任务错误
|
||||
MCSERVER.log("[ Schedule ] [", servername, "] 服务器计划执行时保存 | 已忽略");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//计划任务模块初始化
|
||||
module.exports.init = () => {
|
||||
try {
|
||||
MCSERVER.Schedule.dataModel.load();
|
||||
@ -36,7 +59,7 @@ function createScheduleJobCount(id, time, count, commande, servername, callback,
|
||||
return;
|
||||
}
|
||||
lco++;
|
||||
serverExe(commande);
|
||||
serverExe(servername, commande);
|
||||
callback && callback(commande);
|
||||
|
||||
});
|
||||
|
@ -20,13 +20,20 @@ function CreateScheduleJob(obj) {
|
||||
WebSocketObserver().listener('schedule/list', (data) => {
|
||||
let username = data.WsSession.username;
|
||||
let servername = data.body;
|
||||
let list = MCSERVER.Schedule.dataModel.list;
|
||||
sendlist = [];
|
||||
for (const iterator of list) {
|
||||
if (iterator && iterator.servername == servername) {
|
||||
sendlist.push(iterator);
|
||||
}
|
||||
}
|
||||
|
||||
if (permssion.isCanServer(username, servername)) {
|
||||
let thisServer = serverModel.ServerManager().getServer(servername);
|
||||
response.wsSend(data.ws, 'schedule/list', {
|
||||
username: data.WsSession.username,
|
||||
servername: servername,
|
||||
schedules: MCSERVER.Schedule.dataModel.list
|
||||
schedules: sendlist
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user