mirror of
https://gitlab.com/jusax23/dnc.git
synced 2024-11-22 06:36:40 +01:00
modeule
This commit is contained in:
parent
67fdc60026
commit
efc9ec9e29
2 changed files with 75 additions and 82 deletions
5
main.js
5
main.js
|
@ -1,7 +1,4 @@
|
|||
import dnc from "./manager.js";
|
||||
|
||||
const M = new dnc(process);
|
||||
|
||||
import * as M from "./manager.js";
|
||||
|
||||
M.addShutdownTask(()=>{
|
||||
return new Promise(function(res, rej) {
|
||||
|
|
28
manager.js
28
manager.js
|
@ -1,8 +1,6 @@
|
|||
|
||||
const manager = function(process){
|
||||
var t = this;
|
||||
async function exitHandler(options, exitCode) {
|
||||
t.shutdown().then(()=>{
|
||||
async function exitHandler(options, exitCode) {
|
||||
shutdown().then(()=>{
|
||||
setTimeout(function() {
|
||||
process.exit();
|
||||
}, 1000);
|
||||
|
@ -11,18 +9,18 @@ const manager = function(process){
|
|||
process.exit();
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
[`SIGINT`, `SIGUSR1`, `SIGUSR2`,`SIGTERM`].forEach((eventType) => {
|
||||
}
|
||||
[`SIGINT`, `SIGUSR1`, `SIGUSR2`,`SIGTERM`].forEach((eventType) => {
|
||||
process.on(eventType, exitHandler.bind(null, eventType));
|
||||
});
|
||||
});
|
||||
|
||||
var shutdownTasks = []
|
||||
var shutdownTasks = []
|
||||
|
||||
t.addShutdownTask = function(task,maxDuration=5000){
|
||||
export const addShutdownTask = function(task,maxDuration=5000){
|
||||
shutdownTasks.push({t:task,d:maxDuration});
|
||||
};
|
||||
};
|
||||
|
||||
t.shutdown = function(){
|
||||
export const shutdown = function(){
|
||||
return new Promise((res,rej)=>{
|
||||
console.log("Shuting down ...");
|
||||
|
||||
|
@ -65,9 +63,9 @@ const manager = function(process){
|
|||
}, maxDuration);
|
||||
mayShutdown();
|
||||
});
|
||||
};
|
||||
t.saveShutdown = function(){
|
||||
t.shutdown().then(() => {
|
||||
};
|
||||
export const saveShutdown = function(){
|
||||
shutdown().then(() => {
|
||||
setTimeout(function() { //some save time
|
||||
process.exit();
|
||||
}, 1000);
|
||||
|
@ -76,6 +74,4 @@ const manager = function(process){
|
|||
process.exit();
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
}
|
||||
export default manager;
|
||||
|
|
Loading…
Reference in a new issue