@byted-apaas/server-sdk-node 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hooks/api.js +34 -1
- package/package.json +1 -1
package/hooks/api.js
CHANGED
|
@@ -88,8 +88,41 @@ function getFunctionSync(context, logger) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
return {
|
|
91
|
-
// 多语言函数开发, 走远端
|
|
92
91
|
invoke: async (params) => {
|
|
92
|
+
// 非微服务场景
|
|
93
|
+
if (!utils.isMicroservice()) {
|
|
94
|
+
let func = undefined;
|
|
95
|
+
let requireFunc = utils.getRequireFunc();
|
|
96
|
+
if (requireFunc) {
|
|
97
|
+
try {
|
|
98
|
+
func = requireFunc(funcName);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (func) {
|
|
104
|
+
// 本地调用
|
|
105
|
+
let loopMasks = [funcName];
|
|
106
|
+
let reqCtx = nodeCls.get("loopCtx");
|
|
107
|
+
if (reqCtx && reqCtx.loopMasks && Array.isArray(reqCtx.loopMasks)) {
|
|
108
|
+
if (reqCtx.loopMasks.includes(funcName)) {
|
|
109
|
+
throw new exceptions.InvalidParamError(`Task execution forms a loop.`);
|
|
110
|
+
}
|
|
111
|
+
loopMasks.push(...reqCtx.loopMasks);
|
|
112
|
+
}
|
|
113
|
+
// 修改 source 全局函数
|
|
114
|
+
let ctx = nodeCls.create("loopCtx");
|
|
115
|
+
ctx.loopMasks = loopMasks;
|
|
116
|
+
return await ctx.run(async () => {
|
|
117
|
+
const dynCtx = nodeClsCtx.getDynCtx();
|
|
118
|
+
dynCtx.source = functionSources.globalFunction;
|
|
119
|
+
return await dynCtx.run(async () => {
|
|
120
|
+
return await common.hooks.invoke(func, params, context, logger);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// 远程调用 微服务 | 函数找不到
|
|
93
126
|
return await Request.GetInstance().invokeFuncSync({
|
|
94
127
|
APIName: funcName,
|
|
95
128
|
isInvokeByAPIName: true
|