Merge branch 'develop' of Software_Engineering_I/greenvironment-server into master
commit
a4ce781e41
@ -1,20 +1,20 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [0.9] - 2019-10-29
|
## [0.9] - 2019-10-29
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Graphql Schema
|
- Graphql Schema
|
||||||
- default-config file and generation of config file on startup
|
- default-config file and generation of config file on startup
|
||||||
- DTOs
|
- DTOs
|
||||||
- Home Route
|
- Home Route
|
||||||
- session management
|
- session management
|
||||||
- Sequelize models and integration
|
- Sequelize models and integration
|
||||||
- Sequelize-typescript integration
|
- Sequelize-typescript integration
|
||||||
- error pages
|
- error pages
|
||||||
- pagination for most list types
|
- pagination for most list types
|
||||||
- angular integration by redirecting to `index.html` on not found
|
- angular integration by redirecting to `index.html` on not found
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,96 @@
|
|||||||
|
// tslint:disable:no-console
|
||||||
|
import * as cluster from "cluster";
|
||||||
import App from "./app";
|
import App from "./app";
|
||||||
|
const numCPUs = require("os").cpus().length;
|
||||||
|
|
||||||
/**
|
interface IResourceUsage {
|
||||||
* async main function wrapper.
|
mem: {rss: number, heapTotal: number, heapUsed: number, external: number};
|
||||||
*/
|
cpu: {user: number, system: number};
|
||||||
(async () => {
|
}
|
||||||
const app = new App();
|
|
||||||
await app.init();
|
|
||||||
app.start();
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
interface IClusterData {
|
||||||
|
reqCount: number;
|
||||||
|
workerCount: () => number;
|
||||||
|
workerRes: {[key: string]: IResourceUsage};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cluster.isMaster) {
|
||||||
|
console.log(`[CLUSTER-M] Master ${process.pid} is running`);
|
||||||
|
const clusterData: IClusterData = {
|
||||||
|
reqCount: 0,
|
||||||
|
workerCount: () => Object.keys(cluster.workers).length,
|
||||||
|
// @ts-ignore
|
||||||
|
workerRes: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
clusterData.workerRes.M = {
|
||||||
|
cpu: process.cpuUsage(),
|
||||||
|
mem: process.memoryUsage(),
|
||||||
|
};
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
const log = (msg: string) => {
|
||||||
|
process.stdout.write(" ".padEnd(100) + "\r");
|
||||||
|
process.stdout.write(msg);
|
||||||
|
process.stdout.write(
|
||||||
|
`W: ${clusterData.workerCount()},R: ${clusterData.reqCount},M: ${(() => {
|
||||||
|
let usageString = "";
|
||||||
|
for (const [key, value] of Object.entries(clusterData.workerRes)) {
|
||||||
|
usageString += `${
|
||||||
|
Math.round((value as IResourceUsage).mem.heapUsed / 100000) / 10}MB,`.padEnd(8);
|
||||||
|
}
|
||||||
|
return usageString;
|
||||||
|
})()}`.padEnd(99) + "\r");
|
||||||
|
};
|
||||||
|
cluster.settings.silent = true;
|
||||||
|
|
||||||
|
cluster.on("exit", (worker, code, signal) => {
|
||||||
|
log(`[CLUSTER-M] Worker ${worker.process.pid} died!\n`);
|
||||||
|
delete clusterData.workerRes[worker.id];
|
||||||
|
log("[CLUSTER-M] Starting new worker\n");
|
||||||
|
cluster.fork();
|
||||||
|
});
|
||||||
|
cluster.on("online", (worker) => {
|
||||||
|
worker.process.stdout.on("data", (data) => {
|
||||||
|
log(`[CLUSTER-${worker.id}] ${data}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
cluster.on("message", (worker, message) => {
|
||||||
|
switch (message.cmd) {
|
||||||
|
case "notifyRequest":
|
||||||
|
clusterData.reqCount++;
|
||||||
|
log("");
|
||||||
|
break;
|
||||||
|
case "notifyResources":
|
||||||
|
// @ts-ignore
|
||||||
|
clusterData.workerRes[worker.id] = message.data;
|
||||||
|
log("");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 0; i < numCPUs; i++) {
|
||||||
|
cluster.fork();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* async main function wrapper.
|
||||||
|
*/
|
||||||
|
(async () => {
|
||||||
|
setInterval(() => {
|
||||||
|
process.send({cmd: "notifyResources", data: {
|
||||||
|
cpu: process.cpuUsage(),
|
||||||
|
mem: process.memoryUsage(),
|
||||||
|
}});
|
||||||
|
}, 1000);
|
||||||
|
const app = new App(cluster.worker.id);
|
||||||
|
await app.init();
|
||||||
|
app.start();
|
||||||
|
})();
|
||||||
|
|
||||||
|
console.log(`[CLUSTER] Worker ${process.pid} started`);
|
||||||
|
}
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* An interface for the configuration file
|
||||||
|
*/
|
||||||
|
interface IConfig {
|
||||||
|
/**
|
||||||
|
* Database connection info
|
||||||
|
*/
|
||||||
|
database: {
|
||||||
|
/**
|
||||||
|
* A connection uri for the database. <type>://<user>:<password>@<ip/domain>/<database>
|
||||||
|
*/
|
||||||
|
connectionUri: string;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Configuration for the http server
|
||||||
|
*/
|
||||||
|
server?: {
|
||||||
|
/**
|
||||||
|
* The port to listen on
|
||||||
|
*/
|
||||||
|
port?: number;
|
||||||
|
/**
|
||||||
|
* If cross origin requests should be enabled
|
||||||
|
*/
|
||||||
|
cors?: false;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* The session configuration
|
||||||
|
*/
|
||||||
|
session: {
|
||||||
|
/**
|
||||||
|
* A secure secret to be used for sessions
|
||||||
|
*/
|
||||||
|
secret: string;
|
||||||
|
/**
|
||||||
|
* The maximum cookie age before the session gets deleted
|
||||||
|
*/
|
||||||
|
cookieMaxAge: number;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Configuration for markdown parsing
|
||||||
|
*/
|
||||||
|
markdown?: {
|
||||||
|
/**
|
||||||
|
* The plugins to use for parsing
|
||||||
|
*/
|
||||||
|
plugins: string[];
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Logging configuration
|
||||||
|
*/
|
||||||
|
logging?: {
|
||||||
|
/**
|
||||||
|
* The loglevel that is used for the console and logfiles
|
||||||
|
*/
|
||||||
|
level?: ("silly" | "debug" | "verbose" | "info" | "warn" | "error");
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* The frontend configuration
|
||||||
|
*/
|
||||||
|
frontend?: {
|
||||||
|
/**
|
||||||
|
* Points to the index.html which is loaded as a fallback for angular to work
|
||||||
|
*/
|
||||||
|
angularIndex?: string;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue