adding functionTimeout to settings

adding functionTimeout to settings
This commit is contained in:
Kilian Hertel 2023-06-23 17:42:43 +02:00
parent 234e92db12
commit a44f23c4e2
4 changed files with 38 additions and 1 deletions

View File

@ -360,6 +360,10 @@
name: {value:"_DEFAULT_"},
func: {value:"\nreturn msg;"},
outputs: {value:1},
<<<<<<< Updated upstream
=======
timeout:{value:RED.settings.functionTimeout},
>>>>>>> Stashed changes
noerr: {value:0,required:true,
validate: function(v, opt) {
if (!v) {

View File

@ -503,7 +503,8 @@ module.exports = function(RED) {
RED.nodes.registerType("function",FunctionNode, {
dynamicModuleList: "libs",
settings: {
functionExternalModules: { value: true, exportable: true }
functionExternalModules: { value: true, exportable: true },
functionTimeout: { value:0, exportable: true }
}
});
RED.library.register("functions");

View File

@ -454,6 +454,9 @@ module.exports = {
/** Allow the Function node to load additional npm modules directly */
functionExternalModules: true,
/** a default timeout for function node VM*/
functionTimeout:30,
/** The following property can be used to set predefined values in Global Context.
* This allows extra node modules to be made available with in Function node.
* For example, the following:
@ -465,6 +468,8 @@ module.exports = {
// os:require('os'),
},
/** The maximum number of messages nodes will buffer internally as part of their
* operation. This applies across a range of nodes that operate on message sequences.
* defaults to no limit. A value of 0 also means no limit is applied.

View File

@ -1426,6 +1426,33 @@ describe('function node', function() {
it('check if default function settings grab', function(done) {
RED.seetings.functionTimeout = 0.01;
var flow = [{id:"n1",type:"function",wires:[["n2"]],func:"while(1==1){};\nreturn msg;"}];
helper.load(functionNode, flow, function() {
var n1 = helper.getNode("n1");
n1.receive({payload:"foo",topic: "bar"});
setTimeout(function() {
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function(evt) {
return evt[0].type == "function";
});
logEvents.should.have.length(1);
var msg = logEvents[0][0];
msg.should.have.property('level', helper.log().ERROR);
msg.should.have.property('id', 'n1');
msg.should.have.property('type', 'function');
should.equal(msg.msg.message, 'Script execution timed out after 10ms');
delete RED.settings.functionExternalModules;
done();
} catch(err) {
done(err);
}
},50);
});
});
describe("finalize function", function() {
it('should execute', function(done) {