Deprecate autoInstallModules for externalModules.autoInstall

This commit is contained in:
Nick O'Leary 2020-12-23 22:05:58 +00:00
parent 9b1c114c3f
commit 3151502a3f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 27 additions and 9 deletions

View File

@ -254,7 +254,8 @@ module.exports = {
* Update to internal list of available modules based on what has been actually
* loaded.
*
* The `autoInstallModules` runtime option means the runtime may try to install
* The `externalModules.autoInstall` (previously `autoInstallModules`)
* runtime option means the runtime may try to install
* missing modules after the initial load is complete. If that flag is not set
* this function is used to remove the modules from the registry's saved list.
* @function

View File

@ -123,7 +123,15 @@ function start() {
}
log.info(os.type()+" "+os.release()+" "+os.arch()+" "+os.endianness());
return redNodes.load().then(function() {
let autoInstallModules = false;
if (settings.hasOwnProperty('autoInstallModules')) {
log.warn(log._("runtime.deprecatedOption",{old:"autoInstallModules", new:"externalModules.autoInstall"}));
autoInstallModules = true;
}
if (settings.externalModules) {
// autoInstallModules = autoInstall enabled && (no palette setting || palette install not disabled)
autoInstallModules = settings.externalModules.autoInstall && (!settings.externalModules.palette || settings.externalModules.palette.allowInstall !== false) ;
}
var i;
var nodeErrors = redNodes.getNodeList(function(n) { return n.err!=null;});
var nodeMissing = redNodes.getNodeList(function(n) { return n.module && n.enabled && !n.loaded && !n.err;});
@ -156,12 +164,12 @@ function start() {
for (i in missingModules) {
if (missingModules.hasOwnProperty(i)) {
log.warn(" - "+i+" ("+missingModules[i].version+"): "+missingModules[i].types.join(", "));
if (settings.autoInstallModules && i != "node-red") {
if (autoInstallModules && i != "node-red") {
installingModules.push({id:i,version:missingModules[i].version});
}
}
}
if (!settings.autoInstallModules) {
if (!autoInstallModules) {
log.info(log._("server.removing-modules"));
redNodes.cleanModuleList();
} else if (installingModules.length > 0) {
@ -186,11 +194,19 @@ function start() {
var reinstallAttempts = 0;
var reinstallTimeout;
function reinstallModules(moduleList) {
var promises = [];
var reinstallList = [];
const promises = [];
const reinstallList = [];
const installRetry = 30000;
if (settings.hasOwnProperty('autoInstallModulesRetry')) {
log.warn(log._("runtime.deprecatedOption",{old:"autoInstallModulesRetry", new:"externalModules.autoInstallRetry"}));
installRetry = settings.autoInstallModulesRetry;
}
if (settings.externalModules && settings.externalModules.hasOwnProperty('autoInstallRetry')) {
installRetry = settings.externalModules.autoInstallRetry * 1000;
}
externalModules.autoInstallRetry
for (var i=0;i<moduleList.length;i++) {
if (settings.autoInstallModules && moduleList[i].id != "node-red") {
if (moduleList[i].id != "node-red") {
(function(mod) {
promises.push(redNodes.installModule(mod.id,mod.version).then(m => {
events.emit("runtime-event",{id:"node/added",retain:false,payload:m.nodes});
@ -204,7 +220,7 @@ function reinstallModules(moduleList) {
if (reinstallList.length > 0) {
reinstallAttempts++;
// First 5 at 1x timeout, next 5 at 2x, next 5 at 4x, then 8x
var timeout = (settings.autoInstallModulesRetry||30000) * Math.pow(2,Math.min(Math.floor(reinstallAttempts/5),3));
var timeout = installRetry * Math.pow(2,Math.min(Math.floor(reinstallAttempts/5),3));
reinstallTimeout = setTimeout(function() {
reinstallModules(reinstallList);
},timeout);

View File

@ -42,6 +42,7 @@
"uninstall-failed-long": "Uninstall of module __name__ failed:",
"uninstalled": "Uninstalled module: __name__"
},
"deprecatedOption": "use of __old__ is deprecated. Use __new__ instead",
"unable-to-listen": "Unable to listen on __listenpath__",
"port-in-use": "Error: port in use",
"uncaught-exception": "Uncaught Exception:",