node.js - Firebase 函数执行耗时 60004 毫秒,完成状态为:“超时”错误:超出内存限制。函数调用被中断
问题描述
我每周运行一个脚本。当我的集合中的文档少于 9k 时,一切正常。我已经尝试使用异步函数等到 foreach 结束。但它没有用。你能帮我处理异步功能吗?
代码:
exports.weeklyPointReset = functions.pubsub.schedule('12 04 * * 1').timeZone('UTC').onRun((context) => {
return db.collection('Users').where('weeklyPoint', '!=', 0).orderBy('weeklyPoint', 'desc').get().then(async (snapshot) => {
var counter = 1;
if (snapshot.empty) {
return null;
} else {
const promises = [];
await snapshot.forEach(async (doc) => {
await promises.push(doc.ref.update({ weeklyPoint: 0 }));
});
return await Promise.all(promises);
}
}).catch(error => {
console.log(error);
return null;
});
});
解决方案
感谢您的回复。Renaud,我找到了像你提到的那样增加记忆力的方法。解决方案;
- 转到https://console.cloud.google.com/functions/list,
- 选择函数然后点击编辑,
- 设置内存大小和超时值。(超时最大限制为 540sn)
推荐阅读
- heroku - Heroku Review App URL 只是导致 404
- c# - 使用基于 C# 的工具向 CANoe 配置中的 ECU 发送诊断请求
- cordova - 当应用程序打开或应用程序处于后台时,Phonegap Firebase 推送通知不会触发事件侦听器
- c# - ASP.NET MVC Linq Query 比较变量?
- sql - 如何在 SQL Teradata 中转置表
- python - Python创建区域截图
- regex - 包括所有指定的扩展名,但具有扩展名的特定文件除外
- amazon-web-services - AWS Athena 和角色中的受信任实体
- excel - 在行中找到红色文本时的 Excel 条件格式
- pytorch - 如何在 ConvTranspose3d 之后获取 torch.Size([1, 3, 16, 112, 112]) 而不是 torch.Size([1, 3, 16, 64, 64])