Tro*_*son 5 firebase firebase-realtime-database google-cloud-functions firebase-storage
我使用 Firebase 的免费套餐,并且有一个由实时数据库写入触发的云功能。然后,该函数从 Firebase 存储 (~8 Mb) 下载文件,进行一些处理,然后写回实时数据库。我在整个函数中添加了一些日志语句,以找出为什么花了这么长时间。
当我在本地运行该函数时,它会在 10 秒内完成。为什么云函数内部需要如此长的时间?
函数/index.js
exports.doStuff = functions.database.ref('/my/path/{pushId}')
.onWrite(event => {
const implementation = require('./implementation');
// Variables omitted for brevity...
implementation.process(...variables);
return true;
});
Run Code Online (Sandbox Code Playgroud)
函数/implementation.js
function process(...variables) {
const Storage = require('@google-cloud/storage');
const storage = new Storage();
// Variables omitted for brevity...
const options = {
destination: tempFilePath,
};
storage
.bucket(bucketName)
.file(srcFilename)
.download(options)
.then(() => {
console.log('This takes 3+ minutes for an 8 Mb file');
doStuffWithDownloadedFile(tempFilePath);
})
.catch(error => {
console.error('ERROR: ', error);
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1543 次 |
| 最近记录: |