【问题标题】:Azure Function Calls Javascript Function from another azure function. Is this expected behavior or is this a bug?Azure 函数从另一个 azure 函数调用 Javascript 函数。这是预期的行为还是错误?
【发布时间】:2020-06-04 00:15:11
【问题描述】:

我不确定这是否是预期的行为,但我是否可以完全依赖它。我有一个 Azure 函数,其中包含多个 Javascript 函数。

看来我可以从其他 Azure 函数调用这些 Javascript 函数。这是预期的,我可以依赖这个吗?

我会用下面的例子来说明这一点

// Azure Function 1 :
testFunctionA = () => {
    console.log("This is the 1st function in another azure function");
};

testFunctionB = () => {
    console.log("This is the 2nd function in another azure function");
};

testFunctionC = () => {
    console.log("This is the 3d function in another azure function");
};


module.exports = {
    testFunctionA
};

// Azure function 2:
module.exports = async function (context, req) {
    context.log("JavaScript HTTP trigger function processed a request.");

    testFunctionA();
    testFunctionB();
    testFunctionC();
};

调用 HTTP Trigger Azure Function 2 时,输出如下 尽管这两个函数是单独的 Azure 函数:

This is the 1st function in another azure function
index.js:6
This is the 2nd function in another azure function
index.js:10
This is the 3d function in another azure function

【问题讨论】:

标签: azure azure-functions


【解决方案1】:

以下是在 Function App 中定义 JavaScript 函数的规则:

一个function.json文件用于定义一个触发器,每个function.json文件只能定义一个触发器。还有一个constraint today,一个function.json文件必须是一个,而且只有一个,超过根目录。根目录是带有 host.json 的目录(可能还有 local.settings.json)。

默认情况下,从 function.json 旁边的 index.js 文件导出的 JavaScript 函数是用于处理来自触发器的事件的代码。但是,您也可以使用scriptFile and entryPoint properties 定义此函数的来源。

函数应用程序启动时会加载 JavaScript 函数的所有入口点。这是通过requireing 每个最终将处理触发事件的 JavaScript 函数来完成的。

代码可以并且应该以这种方式在函数之间共享:Manually trigger Azure Function - Time triggered

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    相关资源
    最近更新 更多