gpt4 book ai didi

firebase - 函数执行耗时 60002 毫秒,完成状态为 : 'timeout'

转载 作者:行者123 更新时间:2023-12-05 06:32:03 25 4
gpt4 key购买 nike

<分区>

我有一个大致基于此示例的 Firebase 云函数 https://github.com/firebase/functions-samples/tree/master/image-sharp

今天,在部署一些小的更改时,它给了我这个警告

$ 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-functions 从 ^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-functions ^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;
});

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com