Firebase 函数执行耗时60002毫秒,状态为&x27;超时';
我有一个Firebase云函数,它松散地基于这个示例 今天,在部署一些小更改时,它给了我以下警告Firebase 函数执行耗时60002毫秒,状态为&x27;超时';,firebase,google-cloud-functions,Firebase,Google Cloud Functions,我有一个Firebase云函数,它松散地基于这个示例 今天,在部署一些小更改时,它给了我以下警告 $ firebase deploy --only functions ⚠ functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions
$ firebase deploy --only functions
⚠ functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory.
所以我进行了升级,将firebase函数从^1.0.3升级到^2.0.0
从那时起,我们在运行函数时就得到了这一点
Function execution took 60002 ms, finished with status: 'timeout'
而不是通常的
Function execution took 10 ms, finished with status: 'ok'
我开始剥离我的函数,但即使到了最底层,它仍然会出错
然后,我启动了一个新项目,使用示例函数原样,它的行为方式完全相同。对于firebase函数^2.0.0,它会给出超时错误,但对于^1.0.0,它可以正常工作
这是一个已知的问题吗
谢谢
下面是示例代码
exports.generateThumbnail = functions.storage.object().onFinalize((object) => {
const fileBucket = object.bucket; // The Storage bucket that contains the file.
const filePath = object.name; // File path in the bucket.
const contentType = object.contentType; // File content type.
// Exit if this is triggered on a file that is not an image.
if (!contentType.startsWith('image/')) {
console.log('This is not an image.');
return null;
}
// Get the file name.
const fileName = path.basename(filePath);
// Exit if the image is already a thumbnail.
if (fileName.startsWith('thumb_')) {
console.log('Already a Thumbnail.');
return null;
}
// Download file from bucket.
const bucket = gcs.bucket(fileBucket);
const metadata = {
contentType: contentType,
};
// We add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
const thumbFileName = `thumb_${fileName}`;
const thumbFilePath = path.join(path.dirname(filePath), thumbFileName);
// Create write stream for uploading thumbnail
const thumbnailUploadStream = bucket.file(thumbFilePath).createWriteStream({metadata});
// Create Sharp pipeline for resizing the image and use pipe to read from bucket read stream
const pipeline = sharp();
pipeline
.resize(THUMB_MAX_WIDTH, THUMB_MAX_HEIGHT)
.max()
.pipe(thumbnailUploadStream);
bucket.file(filePath).createReadStream().pipe(pipeline);
const streamAsPromise = new Promise((resolve, reject) =>
thumbnailUploadStream.on('finish', resolve).on('error', reject));
return streamAsPromise.then(() => {
console.log('Thumbnail created successfully');
return null;
});
尝试使用()调用resolve和reject:
我打算发表评论,但这需要我50多个声誉 无论如何,我遇到了同样的问题:
exports.sendNotificationForMessage = functions.firestore.document('chatrooms/{chatroomId}/messages/{messageId}').onCreate((snap, context) => {
const newMessage = snap.data();
const messageContent = newMessage.text;
const senderName = newMessage.senderDisplayName;
const senderId = newMessage.senderId;
const chatroomId = context.params.chatroomId;
console.log(newMessage)
return true;
});
它以状态超时结束
如果firebase function 2.0存在问题,那么将其降级回1.x版的命令是什么?谷歌搜索了一下,但没有找到运气。没有显示函数的代码,我们无法为您做太多。您好,道格,正如我所描述的,它大致基于我发送的示例。然后我继续运行该示例,并能够通过更新到firebase函数的2.0.0来重新创建问题。您是否可以编辑该问题以显示复制该问题的完整、最少的代码?请参阅,您现在可以安装v2.0.1来解决该问题。他们最近发布了。您可以升级以解决此问题
exports.sendNotificationForMessage = functions.firestore.document('chatrooms/{chatroomId}/messages/{messageId}').onCreate((snap, context) => {
const newMessage = snap.data();
const messageContent = newMessage.text;
const senderName = newMessage.senderDisplayName;
const senderId = newMessage.senderId;
const chatroomId = context.params.chatroomId;
console.log(newMessage)
return true;
});