mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Added onExit handler to masterPlugins (see description)
To use the onExit handler, simply add a method called onExit to your exported class. If it returns a promise, the master will wait for it to resolve.
This commit is contained in:
1 parent
f72ea7357e
commit
226e157f69
2 files changed
+25
-10
No files matched your search
@@ -242,8 +242,9 @@ db.items.removeItem = function(object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// store slaves and inventory in a .json full of JSON data
|
// store slaves and inventory in a .json full of JSON data
|
||||||
process.on('SIGINT', function () {
|
process.on('SIGINT', async function () {
|
||||||
console.log('Ctrl-C...');
|
console.log('Ctrl-C...');
|
||||||
|
let exitStartTime = Date.now();
|
||||||
// set insane limit to slave length, if its longer than this we are probably being ddosed or something
|
// set insane limit to slave length, if its longer than this we are probably being ddosed or something
|
||||||
if(slaves && Object.keys(slaves).length < 2000000){
|
if(slaves && Object.keys(slaves).length < 2000000){
|
||||||
console.log("saving to slaves.json");
|
console.log("saving to slaves.json");
|
||||||
@@ -257,6 +258,15 @@ process.on('SIGINT', function () {
|
|||||||
} else if(slaves) {
|
} else if(slaves) {
|
||||||
console.log("Item database too large, not saving ("+Object.keys(slaves).length+")");
|
console.log("Item database too large, not saving ("+Object.keys(slaves).length+")");
|
||||||
}
|
}
|
||||||
|
for(let i in masterPlugins){
|
||||||
|
let plugin = masterPlugins[i];
|
||||||
|
if(plugin.main && plugin.main.onExit && typeof plugin.main.onExit == "function"){
|
||||||
|
let startTime = Date.now();
|
||||||
|
await plugin.main.onExit();
|
||||||
|
console.log("Plugin "+plugin.pluginConfig.name+" exited in "+(Date.now()-startTime)+"ms");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("Exited in "+(Date.now()-exitStartTime)+"ms");
|
||||||
process.exit(2);
|
process.exit(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1083,11 +1093,13 @@ io.on('connection', function (socket) {
|
|||||||
|
|
||||||
// handle plugins on the master
|
// handle plugins on the master
|
||||||
pluginManagement();
|
pluginManagement();
|
||||||
|
masterPlugins = [];
|
||||||
async function pluginManagement(){
|
async function pluginManagement(){
|
||||||
let startPluginLoad = Date.now();
|
let startPluginLoad = Date.now();
|
||||||
let plugins = await getPlugins("sharedPlugins");
|
masterPlugins = await getPlugins("sharedPlugins");
|
||||||
console.log("All plugins loaded in "+(Date.now() - startPluginLoad)+"ms");
|
console.log("All plugins loaded in "+(Date.now() - startPluginLoad)+"ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlugins(pluginDirectory){
|
function getPlugins(pluginDirectory){
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let filesLeft = 0;
|
let filesLeft = 0;
|
||||||
@@ -1115,13 +1127,16 @@ function getPlugins(pluginDirectory){
|
|||||||
--filesLeft;
|
--filesLeft;
|
||||||
if(pluginConfig.masterPlugin){
|
if(pluginConfig.masterPlugin){
|
||||||
let masterPlugin = require(path.resolve(pluginPath, pluginConfig.masterPlugin));
|
let masterPlugin = require(path.resolve(pluginPath, pluginConfig.masterPlugin));
|
||||||
plugins.push(new masterPlugin({
|
plugins.push({
|
||||||
config,
|
main:new masterPlugin({
|
||||||
|
config,
|
||||||
|
pluginConfig,
|
||||||
|
path: pluginPath,
|
||||||
|
socketio: io,
|
||||||
|
express: app,
|
||||||
|
}),
|
||||||
pluginConfig,
|
pluginConfig,
|
||||||
path: pluginPath,
|
});
|
||||||
socketio: io,
|
|
||||||
express: app,
|
|
||||||
}));
|
|
||||||
|
|
||||||
console.log("Loaded plugin "+pluginConfig.name+" in "+(Date.now() - pluginStartedLoading)+"ms");
|
console.log("Loaded plugin "+pluginConfig.name+" in "+(Date.now() - pluginStartedLoading)+"ms");
|
||||||
checkLoadComplete();
|
checkLoadComplete();
|
||||||
|
|||||||
+2
-2
@@ -30,8 +30,8 @@
|
|||||||
"ejs": "^2.5.7",
|
"ejs": "^2.5.7",
|
||||||
"express": "^4.16.2",
|
"express": "^4.16.2",
|
||||||
"express-fileupload": "0.0.6",
|
"express-fileupload": "0.0.6",
|
||||||
"follow-redirects": "^1.4.1",
|
"follow-redirects": "^1.5.0",
|
||||||
"fs-extra": "^1.0.0",
|
"fs-extra": "^6.0.1",
|
||||||
"getmac": "^1.4.0",
|
"getmac": "^1.4.0",
|
||||||
"hash-files": "^1.1.1",
|
"hash-files": "^1.1.1",
|
||||||
"html5-validator": "^1.0.7",
|
"html5-validator": "^1.0.7",
|
||||||
|
|||||||
Reference in new issue
Block a user