Remote JS executor to work with tb-node of previous version
This commit is contained in:
parent
831332be7b
commit
2d262146ad
@ -41,34 +41,34 @@ message RemoteJsResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message JsCompileRequest {
|
message JsCompileRequest {
|
||||||
string scriptHash = 1;
|
string functionName = 3;
|
||||||
string functionName = 2;
|
string scriptBody = 4;
|
||||||
string scriptBody = 3;
|
string scriptHash = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message JsReleaseRequest {
|
message JsReleaseRequest {
|
||||||
string scriptHash = 1;
|
string functionName = 3;
|
||||||
string functionName = 2;
|
string scriptHash = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message JsReleaseResponse {
|
message JsReleaseResponse {
|
||||||
bool success = 1;
|
bool success = 1;
|
||||||
string scriptHash = 2;
|
string scriptHash = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message JsCompileResponse {
|
message JsCompileResponse {
|
||||||
bool success = 1;
|
bool success = 1;
|
||||||
string scriptHash = 2;
|
JsInvokeErrorCode errorCode = 4;
|
||||||
JsInvokeErrorCode errorCode = 3;
|
string errorDetails = 5;
|
||||||
string errorDetails = 4;
|
string scriptHash = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message JsInvokeRequest {
|
message JsInvokeRequest {
|
||||||
string scriptHash = 1;
|
string functionName = 3;
|
||||||
string functionName = 2;
|
string scriptBody = 4;
|
||||||
string scriptBody = 3;
|
int32 timeout = 5;
|
||||||
int32 timeout = 4;
|
repeated string args = 6;
|
||||||
repeated string args = 5;
|
string scriptHash = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message JsInvokeResponse {
|
message JsInvokeResponse {
|
||||||
|
|||||||
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
|
|
||||||
export interface TbMessage {
|
export interface TbMessage {
|
||||||
|
scriptIdMSB: string; // deprecated
|
||||||
|
scriptIdLSB: string; // deprecated
|
||||||
scriptHash: string;
|
scriptHash: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import config from 'config';
|
|||||||
import { _logger } from '../config/logger';
|
import { _logger } from '../config/logger';
|
||||||
import { JsExecutor, TbScript } from './jsExecutor';
|
import { JsExecutor, TbScript } from './jsExecutor';
|
||||||
import { performance } from 'perf_hooks';
|
import { performance } from 'perf_hooks';
|
||||||
import { isString, parseJsErrorDetails, toUUIDString, UUIDFromBuffer, UUIDToBits } from './utils';
|
import { isString, parseJsErrorDetails, toUUIDString, UUIDFromBuffer, UUIDToBits, isNotUUID } from './utils';
|
||||||
import { IQueue } from '../queue/queue.models';
|
import { IQueue } from '../queue/queue.models';
|
||||||
import {
|
import {
|
||||||
JsCompileRequest,
|
JsCompileRequest,
|
||||||
@ -176,7 +176,7 @@ export class JsInvokeMessageProcessor {
|
|||||||
this.logger.debug('[%s] Sending success invoke response, scriptId: [%s]', requestId, scriptId);
|
this.logger.debug('[%s] Sending success invoke response, scriptId: [%s]', requestId, scriptId);
|
||||||
this.sendResponse(requestId, responseTopic, headers, scriptId, undefined, invokeResponse);
|
this.sendResponse(requestId, responseTopic, headers, scriptId, undefined, invokeResponse);
|
||||||
} else {
|
} else {
|
||||||
let err = {
|
const err = {
|
||||||
name: 'Error',
|
name: 'Error',
|
||||||
message: 'script invocation result exceeds maximum allowed size of ' + maxResultSize + ' symbols'
|
message: 'script invocation result exceeds maximum allowed size of ' + maxResultSize + ' symbols'
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ export class JsInvokeMessageProcessor {
|
|||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
let errorCode = COMPILATION_ERROR;
|
let errorCode = COMPILATION_ERROR;
|
||||||
if (err && isString(err.name) && err.name.includes('script body not found')) {
|
if (err?.name === 'script body not found') {
|
||||||
errorCode = NOT_FOUND_ERROR;
|
errorCode = NOT_FOUND_ERROR;
|
||||||
}
|
}
|
||||||
const invokeResponse = JsInvokeMessageProcessor.createInvokeResponse("", false, errorCode, err);
|
const invokeResponse = JsInvokeMessageProcessor.createInvokeResponse("", false, errorCode, err);
|
||||||
@ -301,12 +301,26 @@ export class JsInvokeMessageProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static createCompileResponse(scriptId: string, success: boolean, errorCode?: number, err?: any): JsCompileResponse {
|
private static createCompileResponse(scriptId: string, success: boolean, errorCode?: number, err?: any): JsCompileResponse {
|
||||||
return {
|
if (isNotUUID(scriptId)) {
|
||||||
errorCode: errorCode,
|
return {
|
||||||
success: success,
|
errorCode: errorCode,
|
||||||
errorDetails: parseJsErrorDetails(err),
|
success: success,
|
||||||
scriptHash: scriptId,
|
errorDetails: parseJsErrorDetails(err),
|
||||||
};
|
scriptIdMSB: "0",
|
||||||
|
scriptIdLSB: "0",
|
||||||
|
scriptHash: scriptId
|
||||||
|
};
|
||||||
|
} else { // this is for backward compatibility (to be able to work with tb-node of previous version) - todo: remove in the next release
|
||||||
|
let scriptIdBits = UUIDToBits(scriptId);
|
||||||
|
return {
|
||||||
|
errorCode: errorCode,
|
||||||
|
success: success,
|
||||||
|
errorDetails: parseJsErrorDetails(err),
|
||||||
|
scriptIdMSB: scriptIdBits[0],
|
||||||
|
scriptIdLSB: scriptIdBits[1],
|
||||||
|
scriptHash: ""
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static createInvokeResponse(result: string, success: boolean, errorCode?: number, err?: any): JsInvokeResponse {
|
private static createInvokeResponse(result: string, success: boolean, errorCode?: number, err?: any): JsInvokeResponse {
|
||||||
@ -319,14 +333,26 @@ export class JsInvokeMessageProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static createReleaseResponse(scriptId: string, success: boolean): JsReleaseResponse {
|
private static createReleaseResponse(scriptId: string, success: boolean): JsReleaseResponse {
|
||||||
return {
|
if (isNotUUID(scriptId)) {
|
||||||
success: success,
|
return {
|
||||||
scriptHash: scriptId,
|
success: success,
|
||||||
};
|
scriptIdMSB: "0",
|
||||||
|
scriptIdLSB: "0",
|
||||||
|
scriptHash: scriptId,
|
||||||
|
};
|
||||||
|
} else { // todo: remove in the next release
|
||||||
|
let scriptIdBits = UUIDToBits(scriptId);
|
||||||
|
return {
|
||||||
|
success: success,
|
||||||
|
scriptIdMSB: scriptIdBits[0],
|
||||||
|
scriptIdLSB: scriptIdBits[1],
|
||||||
|
scriptHash: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getScriptId(request: TbMessage): string {
|
private static getScriptId(request: TbMessage): string {
|
||||||
return request.scriptHash;
|
return request.scriptHash ? request.scriptHash : toUUIDString(request.scriptIdMSB, request.scriptIdLSB);
|
||||||
}
|
}
|
||||||
|
|
||||||
private incrementUseScriptId(scriptId: string) {
|
private incrementUseScriptId(scriptId: string) {
|
||||||
|
|||||||
@ -58,3 +58,7 @@ export function parseJsErrorDetails(err: any): string | undefined {
|
|||||||
}
|
}
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNotUUID(candidate: string) {
|
||||||
|
return candidate.length != 36 || !candidate.includes('-');
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user