mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add status capability to function node
This commit is contained in:
parent
4772bca14a
commit
0343de9f34
@ -57,6 +57,7 @@ module.exports = function(RED) {
|
|||||||
"error:__node__.error,"+
|
"error:__node__.error,"+
|
||||||
"warn:__node__.warn,"+
|
"warn:__node__.warn,"+
|
||||||
"on:__node__.on,"+
|
"on:__node__.on,"+
|
||||||
|
"status:__node__.status,"+
|
||||||
"send:function(msgs){ __node__.send(__msgid__,msgs);}"+
|
"send:function(msgs){ __node__.send(__msgid__,msgs);}"+
|
||||||
"};\n"+
|
"};\n"+
|
||||||
this.func+"\n"+
|
this.func+"\n"+
|
||||||
@ -70,17 +71,20 @@ module.exports = function(RED) {
|
|||||||
log: function() {
|
log: function() {
|
||||||
node.log.apply(node, arguments);
|
node.log.apply(node, arguments);
|
||||||
},
|
},
|
||||||
error: function(){
|
error: function() {
|
||||||
node.error.apply(node, arguments);
|
node.error.apply(node, arguments);
|
||||||
},
|
},
|
||||||
warn: function() {
|
warn: function() {
|
||||||
node.warn.apply(node, arguments);
|
node.warn.apply(node, arguments);
|
||||||
},
|
},
|
||||||
send: function(id,msgs) {
|
send: function(id, msgs) {
|
||||||
sendResults(node,id,msgs);
|
sendResults(node, id, msgs);
|
||||||
},
|
},
|
||||||
on: function() {
|
on: function() {
|
||||||
node.on.apply(node,arguments);
|
node.on.apply(node, arguments);
|
||||||
|
},
|
||||||
|
status: function() {
|
||||||
|
node.status.apply(node, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
@ -100,7 +104,7 @@ module.exports = function(RED) {
|
|||||||
sendResults(this,msg._msgid,context.results);
|
sendResults(this,msg._msgid,context.results);
|
||||||
|
|
||||||
var duration = process.hrtime(start);
|
var duration = process.hrtime(start);
|
||||||
var converted = Math.floor((duration[0]* 1e9 + duration[1])/10000)/100;
|
var converted = Math.floor((duration[0] * 1e9 + duration[1])/10000)/100;
|
||||||
this.metric("duration", msg, converted);
|
this.metric("duration", msg, converted);
|
||||||
if (process.env.NODE_RED_FUNCTION_TIME) {
|
if (process.env.NODE_RED_FUNCTION_TIME) {
|
||||||
this.status({fill:"yellow",shape:"dot",text:""+converted});
|
this.status({fill:"yellow",shape:"dot",text:""+converted});
|
||||||
@ -111,7 +115,7 @@ module.exports = function(RED) {
|
|||||||
var errorMessage;
|
var errorMessage;
|
||||||
var stack = err.stack.split(/\r?\n/);
|
var stack = err.stack.split(/\r?\n/);
|
||||||
if (stack.length > 0) {
|
if (stack.length > 0) {
|
||||||
while(line < stack.length && stack[line].indexOf("ReferenceError") !== 0) {
|
while (line < stack.length && stack[line].indexOf("ReferenceError") !== 0) {
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,9 +123,9 @@ module.exports = function(RED) {
|
|||||||
errorMessage = stack[line];
|
errorMessage = stack[line];
|
||||||
var m = /:(\d+):(\d+)$/.exec(stack[line+1]);
|
var m = /:(\d+):(\d+)$/.exec(stack[line+1]);
|
||||||
if (m) {
|
if (m) {
|
||||||
var line = Number(m[1])-1;
|
var lineno = Number(m[1])-1;
|
||||||
var cha = m[2];
|
var cha = m[2];
|
||||||
errorMessage += " (line "+line+", col "+cha+")";
|
errorMessage += " (line "+lineno+", col "+cha+")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user