【发布时间】:2021-06-09 17:46:56
【问题描述】:
我为 Firebase 编写了一个可调用 https 的云函数,应该删除文件夹中的所有文件。看起来是这样的:
import * as functions from "firebase-functions";
const admin = require('firebase-admin');
admin.initializeApp();
const {Storage} = require("@google-cloud/storage");
const storage = new Storage({keyFilename: "myserviceaccount.json"});
const fileBucket = "myfilebucket";
exports.deleteFolder = functions.https.onCall(async (data, context) => {
if (!context.auth) {
throw new functions.https.HttpsError(
"unauthenticated",
"only authenticated users can add requests"
);
}
const bucket = storage.bucket(fileBucket);
return bucket.deleteFiles({
prefix: `${data.folderName}`,
}, function(err:any) {
if (err) {
console.log(err);
} else {
// eslint-disable-next-line max-len
console.log(`All the Firebase Storage files in users/${data.folderName}/ have been deleted`);
}
});
});
效果很好。但是我的文件夹有时会包含很多文件,因此我在部署此功能时获得的标准时间限制 60 秒有时不足以删除文件夹内的所有文件。所以我想将计算时间限制提高到 540 秒,女巫是根据 Cloud Functions 我可以获得的最大计算时间。但我找不到这样做的可能性。
如何提高单个 https 可调用函数的时间限制?
【问题讨论】:
标签: node.js typescript firebase google-cloud-functions firebase-storage