mirror of
https://github.com/lucaspalomodevelop/JSSTE_APP.git
synced 2026-03-13 00:07:22 +00:00
update logger uuid | clustering | little fixes
This commit is contained in:
parent
a87a686d32
commit
b6b3244366
@ -1,3 +1,4 @@
|
||||
const { time } = require("console");
|
||||
const { get } = require("express/lib/request");
|
||||
const res = require("express/lib/response");
|
||||
let fs = require("fs");
|
||||
@ -11,10 +12,13 @@ let instance = null;
|
||||
* @returns
|
||||
*/
|
||||
module.exports = function (optPath) {
|
||||
let timestemp = Math.round(new Date().getTime() / 1000);
|
||||
|
||||
if (instance !== null) {
|
||||
return instance;
|
||||
if (instance.meta.timestemp + 60 >= timestemp) return instance;
|
||||
}
|
||||
|
||||
console.log("creating new config instance");
|
||||
let cname = ".jssteconfig";
|
||||
let cpath = path.join(__dirname, "..", "..");
|
||||
let conf = getCurrentConfig(cpath);
|
||||
@ -28,9 +32,8 @@ module.exports = function (optPath) {
|
||||
function getMeta(el) {
|
||||
return {
|
||||
load: el.name,
|
||||
timestemp: new Date().getTime(),
|
||||
timestemp: Math.round(new Date().getTime() / 1000),
|
||||
workingdir: process.cwd(),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ jobs.Start = function () {
|
||||
};
|
||||
|
||||
jobs.Stop = function () {
|
||||
console.log("Stopping Cronjobs");
|
||||
jobsArray.forEach((job) => {
|
||||
job.stop();
|
||||
});
|
||||
|
||||
@ -5,6 +5,15 @@ let name;
|
||||
var log_file;
|
||||
updateData();
|
||||
var log_stdout = process.stdout;
|
||||
var currentuuid = uuid();
|
||||
|
||||
function uuid() {
|
||||
return "xxxxx".replace(/[xy]/g, function (c) {
|
||||
var r = (Math.random() * 16) | 0,
|
||||
v = c == "x" ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
function updateData() {
|
||||
name = "log_" + moment().format("YYYY-MM-DD") + ".log";
|
||||
@ -16,7 +25,9 @@ function updateData() {
|
||||
console.log = function (d) {
|
||||
name = "log_" + moment().format("YYYY-MM-DD") + ".log";
|
||||
|
||||
d = `[ ${moment().format("YYYY-MM-DD HH:mm:ss")}] ${util.format(d)} \n`;
|
||||
d = `[ ${moment().format(
|
||||
"YYYY-MM-DD HH:mm:ss"
|
||||
)}] [${currentuuid}] ${util.format(d)} \n`;
|
||||
log_file.write(d);
|
||||
log_stdout.write(d);
|
||||
};
|
||||
|
||||
75
src/index.js
75
src/index.js
@ -1,27 +1,56 @@
|
||||
let logger = require("./helper/logger");
|
||||
let conf = require("./helper/conf")();
|
||||
let websrv = require("./websrv")(conf);
|
||||
let jobs = require("./helper/cronjobs");
|
||||
let open = require("open");
|
||||
const cluster = require("cluster");
|
||||
let os = require("os");
|
||||
|
||||
/**
|
||||
* @description
|
||||
* Starts the server
|
||||
*/
|
||||
websrv.slisten((host, port) => {
|
||||
console.log("Server started on http://" + host + ":" + port);
|
||||
open("http://" + host + ":" + port + "/dashboard");
|
||||
});
|
||||
const totalCPUs = require("os").cpus().length;
|
||||
|
||||
/**
|
||||
* @description
|
||||
* Stops the server
|
||||
*/
|
||||
process.on("SIGINT", () => {
|
||||
logger.DeleteOldLogs();
|
||||
console.log("Cronjob Beenden ...");
|
||||
jobs.Stop();
|
||||
console.log("Web-Server Beenden ...");
|
||||
websrv.close();
|
||||
process.exit();
|
||||
});
|
||||
os.setPriority(os.constants.priority.PRIORITY_HIGHEST);
|
||||
|
||||
if (cluster.isMaster) {
|
||||
let jobs = require("./helper/cronjobs");
|
||||
let open = require("open");
|
||||
|
||||
console.log(`Number of CPUs is ${totalCPUs}`);
|
||||
console.log(`Master ${process.pid} is running`);
|
||||
|
||||
// Fork workers.
|
||||
for (let i = 0; i < totalCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
|
||||
console.log(
|
||||
"Server started on http://" +
|
||||
conf.webserver.host +
|
||||
":" +
|
||||
conf.webserver.port
|
||||
);
|
||||
open(
|
||||
"http://" + conf.webserver.host + ":" + conf.webserver.port + "/dashboard"
|
||||
);
|
||||
|
||||
cluster.on("exit", (worker, code, signal) => {
|
||||
console.log(`worker ${worker.process.pid} died`);
|
||||
cluster.fork();
|
||||
});
|
||||
|
||||
process.on("SIGINT", async () => {
|
||||
console.log("Stopping JSSTE APP Master ...");
|
||||
logger.DeleteOldLogs();
|
||||
jobs.Stop();
|
||||
process.exit();
|
||||
});
|
||||
} else {
|
||||
let websrv = require("./websrv")(conf);
|
||||
console.log(`Worker ${process.pid} started`);
|
||||
websrv.slisten((host, port) => {
|
||||
console.log(`Worker ${process.pid} is listening`);
|
||||
// console.log("Server started on http://" + host + ":" + port);
|
||||
// open("http://" + host + ":" + port + "/dashboard");
|
||||
});
|
||||
process.on("SIGINT", async () => {
|
||||
console.log("Stopping JSSTE APP Worker ...");
|
||||
websrv.close();
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
const conf = require("../../helper/conf")();
|
||||
let conf = require("../../helper/conf")();
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const States = require("../../helper/states");
|
||||
const logger = require("../../helper/logger");
|
||||
|
||||
router.get("/conf", (req, res) => {
|
||||
conf = require("../../helper/conf")();
|
||||
res.json(conf);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user