implement flows runtime stop/start API and UI

This commit is contained in:
Steve-Mcl
2022-06-08 21:56:17 +01:00
parent 62cd3b2061
commit 68331fc40c
18 changed files with 657 additions and 63 deletions

View File

@@ -261,6 +261,7 @@ function getFlows() {
async function start(type,diff,muteLog) {
type = type||"full";
let reallyStarted = started
started = true;
var i;
// If there are missing types, report them, emit the necessary runtime event and return
@@ -365,24 +366,42 @@ async function start(type,diff,muteLog) {
}
}
// Having created or updated all flows, now start them.
for (id in activeFlows) {
if (activeFlows.hasOwnProperty(id)) {
try {
activeFlows[id].start(diff);
let startFlows = true
try {
startFlows = settings.get('flowsRunStateRequested');
} catch(err) {
}
startFlows = (startFlows !== "stop");
// Create a map of node id to flow id and also a subflowInstance lookup map
var activeNodes = activeFlows[id].getActiveNodes();
Object.keys(activeNodes).forEach(function(nid) {
activeNodesToFlow[nid] = id;
});
} catch(err) {
console.log(err.stack);
if (startFlows) {
for (id in activeFlows) {
if (activeFlows.hasOwnProperty(id)) {
try {
activeFlows[id].start(diff);
// Create a map of node id to flow id and also a subflowInstance lookup map
var activeNodes = activeFlows[id].getActiveNodes();
Object.keys(activeNodes).forEach(function(nid) {
activeNodesToFlow[nid] = id;
});
} catch(err) {
console.log(err.stack);
}
}
}
reallyStarted = true;
events.emit("flows:started", {config: activeConfig, type: type, diff: diff});
// Deprecated event
events.emit("nodes-started");
} else {
started = false;
}
events.emit("flows:started", {config: activeConfig, type: type, diff: diff});
// Deprecated event
events.emit("nodes-started");
const state = {
started: reallyStarted,
state: reallyStarted ? "started" : "stopped",
}
events.emit("runtime-event",{id:"flows-run-state", payload: state, retain:true});
if (credentialsPendingReset === true) {
credentialsPendingReset = false;
@@ -390,7 +409,7 @@ async function start(type,diff,muteLog) {
events.emit("runtime-event",{id:"runtime-state",retain:true});
}
if (!muteLog) {
if (!muteLog && reallyStarted) {
if (type !== "full") {
log.info(log._("nodes.flows.started-modified-"+type));
} else {
@@ -471,6 +490,7 @@ function stop(type,diff,muteLog) {
}
}
events.emit("flows:stopped",{config: activeConfig, type: type, diff: diff});
events.emit("runtime-event",{id:"flows-run-state", payload: {started: false, state: "stopped"}, retain:true});
// Deprecated event
events.emit("nodes-stopped");
});