Rework Function node module integration

This commit is contained in:
Nick O'Leary
2021-02-12 18:14:13 +00:00
parent 4a1d66f210
commit 9c09ee3b71
20 changed files with 800 additions and 1384 deletions

View File

@@ -187,35 +187,35 @@ function setFlows(_config,_credentials,type,muteLog,forceStart,user) {
});
}
return configSavePromise
.then(function(flowRevision) {
if (!isLoad) {
log.debug("saved flow revision: "+flowRevision);
}
activeConfig = {
flows:config,
rev:flowRevision
};
activeFlowConfig = newFlowConfig;
if (forceStart || started) {
// Flows are running (or should be)
// Stop the active flows (according to deploy type and the diff)
return stop(type,diff,muteLog).then(() => {
// Once stopped, allow context to remove anything no longer needed
return context.clean(activeFlowConfig)
}).then(() => {
// Start the active flows
start(type,diff,muteLog).then(() => {
events.emit("runtime-event",{id:"runtime-deploy",payload:{revision:flowRevision},retain: true});
});
// Return the new revision asynchronously to the actual start
return flowRevision;
}).catch(function(err) { })
} else {
events.emit("runtime-event",{id:"runtime-deploy",payload:{revision:flowRevision},retain: true});
}
});
return configSavePromise.then(flowRevision => {
if (!isLoad) {
log.debug("saved flow revision: "+flowRevision);
}
activeConfig = {
flows:config,
rev:flowRevision
};
activeFlowConfig = newFlowConfig;
if (forceStart || started) {
// Flows are running (or should be)
// Stop the active flows (according to deploy type and the diff)
return stop(type,diff,muteLog).then(() => {
// Once stopped, allow context to remove anything no longer needed
return context.clean(activeFlowConfig)
}).then(() => {
// Start the active flows
start(type,diff,muteLog).then(() => {
events.emit("runtime-event",{id:"runtime-deploy",payload:{revision:flowRevision},retain: true});
});
// Return the new revision asynchronously to the actual start
return flowRevision;
}).catch(function(err) { })
} else {
events.emit("runtime-event",{id:"runtime-deploy",payload:{revision:flowRevision},retain: true});
}
});
}
function getNode(id) {
@@ -246,7 +246,7 @@ function getFlows() {
return activeConfig;
}
function start(type,diff,muteLog) {
async function start(type,diff,muteLog) {
type = type||"full";
started = true;
var i;
@@ -271,7 +271,21 @@ function start(type,diff,muteLog) {
log.info(" "+settings.userDir);
}
events.emit("runtime-event",{id:"runtime-state",payload:{error:"missing-types", type:"warning",text:"notification.warnings.missing-types",types:activeFlowConfig.missingTypes},retain:true});
return Promise.resolve();
return;
}
try {
await typeRegistry.checkFlowDependencies(activeConfig.flows);
} catch(err) {
log.info("Failed to load external modules required by this flow:");
const missingModules = [];
for (i=0;i<err.length;i++) {
let errMessage = err[i].error.toString()
missingModules.push({module:err[i].module.module, error: err[i].error.code || err[i].error.toString()})
log.info(` - ${err[i].module.spec} [${err[i].error.code || "unknown_error"}]`);
}
events.emit("runtime-event",{id:"runtime-state",payload:{error:"missing-modules", type:"warning",text:"notification.warnings.missing-modules",modules:missingModules},retain:true});
return;
}
// In safe mode, don't actually start anything, emit the necessary runtime event and return
@@ -280,7 +294,7 @@ function start(type,diff,muteLog) {
log.info(log._("nodes.flows.safe-mode"));
log.info("*****************************************************************")
events.emit("runtime-event",{id:"runtime-state",payload:{error:"safe-mode", type:"warning",text:"notification.warnings.safe-mode"},retain:true});
return Promise.resolve();
return;
}
if (!muteLog) {
@@ -370,7 +384,7 @@ function start(type,diff,muteLog) {
log.info(log._("nodes.flows.started-flows"));
}
}
return Promise.resolve();
return;
}
function stop(type,diff,muteLog) {