函数执行耗时60002 ms,状态为:“超时" [英] Function execution took 60002 ms, finished with status: 'timeout'

查看:70
本文介绍了函数执行耗时60002 ms,状态为:“超时"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Firebase云功能,该功能大致基于此示例 https://github.com/firebase/functions-samples/tree/master/image-sharp

I have a Firebase cloud function that is loosely based on this example https://github.com/firebase/functions-samples/tree/master/image-sharp

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

Today, when deploying some small changes it gave me this warning

$ 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

so I did the upgrade, which upgraded firebase-functions from ^1.0.3 to ^2.0.0

从那以后,在运行函数时一直得到

since then have been getting this when running the function

Function execution took 60002 ms, finished with status: 'timeout'

代替通常的

Function execution took 10 ms, finished with status: 'ok'

我开始精简我的功能,但即使是白手起家,它仍然会出现错误.

I started stripping down my function but even going down to bare bones it was still getting the error.

然后我使用示例函数按原样启动了一个新项目,它的行为方式完全相同.使用firebase函数^ 2.0.0时,它会给出超时错误,但是使用^ 1.0.0时,它可以正常工作.

I then started a new project used the example function as is and it behaves exactly the same way. With firebase-functions ^2.0.0 it gives the timeout error but with ^1.0.0 it works fine.

这是一个已知问题吗?

谢谢

这是示例代码

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;
  });

推荐答案

我要发表评论,但这需要50多个信誉.....

I was going to comment but it requires me 50+ reputations.....

无论如何,我遇到了同样的问题:

Anyway, I am experiencing the same problem:

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版本的命令是什么?用谷歌搜索,但没有运气.

If it's a problem with firebase-function 2.0, what is the command to downgrade it back to version 1.x? Googled about it but no luck.

这篇关于函数执行耗时60002 ms,状态为:“超时"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆