javascript - 我传递的函数并没有被 azure function app 运行
问题描述
我正在尝试让我的函数应用程序将 dta 记录到 azure 表中。我按照示例进行了操作,但是未运行我作为回调提供的函数。
我已经尝试在我的机器上本地的节点服务器上运行它并且它工作正常,因此我认为这是 azure 的问题?我还尝试创建一个没有不必要节点包的新函数应用程序,以查看它们是否是问题所在,但这没有帮助。
module.exports = async function(context, req) {
var tableSvc = azure.createTableService('account name', 'access key');
tableSvc.createTableIfNotExists('mytable', function(error, result, response) {
context.log("Reached this point");
if (!error) {
context.log(result);
}
});
}
我希望在函数应用日志中看到“到达这一点”以及结果——如果没有错误的话。
解决方案
该功能在您将请求发送到存储之后但在您点击之前完成,context.log("Reached this point");
因此即使正在创建表也不会发生日志记录。由于createTableIfNotExists()
不返回可以等待的承诺,因此您需要同步运行该函数并使用它context.done()
来让运行时知道该函数何时完成。
module.exports = function(context, req) {
var tableSvc = azure.createTableService('account name', 'access key');
tableSvc.createTableIfNotExists('mytable', function(error, result, response) {
context.log("Reached this point");
if (!error) {
context.log(result);
}
context.done();
});
}
推荐阅读
- spring-boot - UserInfoEndpoint 中缺少客户端注册所需的 UserInfo Uri
- ansible - Ansible 询问成为特定主机
- cookies - 从 Postman 拦截器中提取 cookie
- dart - 颤振/模拟。使用 mockito 测试 API 提供程序,api 标头有问题
- spring - 如何将 Swagger API 从一个 Spring 应用程序包含到另一个 Spring 应用程序中?
- jmeter - 仅收到一个远程引擎的结果后测试结束,导致其他引擎连接被拒绝
- java - 无法在 jsp 中使用 ${data} 显示数据,而 request.getAttribute("data") 确实返回了值
- javascript - 从 aspnet 核心到 javascript 的特殊字符问题
- excel - 打开选定表的连接属性
- reactjs - Css 不适用于由 innerHTML 插入的元素