Merge pull request #48 from servisbot/MVP-9730

undefined fix, plus extra cater for error now
This commit is contained in:
Steve Walsh 2023-11-13 10:53:04 +00:00 committed by GitHub
commit 0c262fba56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 14 deletions

View File

@ -14,6 +14,10 @@ To make a change to the node-red runtime being used by K4 avalanche:
When doing dev work dont try to link into k4/k5 it just causes issue, instead just go into the node-modules of k4/k5 and make your changes in there
# CHANGE-LOG
## 0.18.7-patch-13
2023-11-13
- Small fix for codefile logic
## 0.18.7-patch-12
2023-11-09
- Added code file as an alternative to vm for function nodes

View File

@ -252,28 +252,26 @@ module.exports = function (RED) {
} = RED;
if (codefile) {
workerId = workerId.split(":::")[0];
const nodeId = this.id.split(`${organization}-${workerId}-`)[1];
try {
const messageToSend = clone(msg);
delete messageToSend.logger;
const beforeCodefile = process.hrtime();
const {
result: {
Result: { msg: responseMessage },
payload: {
result,
error
},
} = await codefile.run({ srcCode: this.func, context: { msg } });
requestId
} = await codefile.run({ srcCode: this.func, context: { msg } });
const afterCodefile = process.hrtime(beforeCodefile);
responseMessage.logger = logger;
payloadValidator.verify(responseMessage);
// to make function node return result from code file uncomment this line, and comment out the sendResults above
// sendResults(this,msg._msgid, responseMessage);
workerId = workerId.split(":::")[0];
const nodeId = this.id.split(`${organization}-${workerId}-`)[1];
lambdaRequestId = responseMessage.lambdaRequestId;
const metrics = {
lambdaRequestId: requestId,
action:'codefile-success',
organization,
workerId: workerId,
nodeId: nodeId,
@ -287,12 +285,24 @@ module.exports = function (RED) {
) / 100
}ms`,
};
if(result){
// not required right now since we dont go via this path
// const responseMessage = result.msg
// responseMessage.logger = logger;
// payloadValidator.verify(responseMessage);
// sendResults(this,msg._msgid, responseMessage);
}
else{
metrics.error = error;
metrics.action = 'codefile-error';
}
logger.info(JSON.stringify(metrics, null, 2));
} catch (e) {
logger.error(e)
logger.error({
message: "Error running codefile",
error: e,
lambdaRequestId,
action:'codefile-error',
error: e.message,
organization,
workerId: workerId,
nodeId: nodeId,

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@servisbot/node-red",
"version": "0.18.7-patch-11",
"version": "0.18.7-patch-12",
"lockfileVersion": 1,
"requires": true,
"dependencies": {