为什么我所有的Firebase云功能都超时了? [英] Why are all of my firebase cloud functions timing out?

查看:44
本文介绍了为什么我所有的Firebase云功能都超时了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Firebase云函数来创建外部JSON API的代理.但是现在,我只是试图将其设置好.

I'm trying to use firebase cloud functions to create a proxy to an external json api. But right now I'm just trying to get it all set up.

我写了这个函数:

exports.helloWorld = functions.https.onRequest((request, response) => {
  request.get('http://www.google.com', function (error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log(body) // Print the google web page.
    }
  })
});

然后我运行firebase函数模拟器并运行

I then run the firebase functions emulator and run

curl http://localhost:5000/<project-id>/us-central1/helloWorld

它返回一条消息,说明该函数已被触发,开始执行,但随后它只是坐在那里旋转,直到最终超时.

It returns a message saying the function was triggered, starting execution, but then it just sits there and spins until eventually it times out.

{"error":{"code":500,"status":"INTERNAL","message":"function execution attempt timed out"}}

我不确定自己在做什么错.

I'm not sure what I'm doing wrong.

........

编辑

此功能运行完美:

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send('test');
})

推荐答案

使用Cloud Functions,HTTPS类型的函数必须将结果写入客户端,以指示该函数已完成执行.在写入结果之前,假定该函数仍在运行异步工作.

With Cloud Functions, HTTPS type functions are obliged to write a result to the client to indicate that the function is done executing. Until a result is written, the function is assumed to still be running something asynchronous work.

因此,当您的请求完成时,即使它为空,您也应该发送一些响应.不幸的是,您已经用另一个对象遮盖了主要的 response 对象,因此您可能应该重命名其中之一:

So, when your request is complete, you should be sending some response, even if it's empty. Unfortunately, you've shadowed your primary response object with another one, so you should probably rename one of them:

exports.helloWorld = functions.https.onRequest((request, response) => {
  request.get('http://www.google.com', function (error, res, body) {
    if (!error && res.statusCode == 200) {
      console.log(body) // Print the google web page.
    }
    return response.send("") // this terminates the function
  })
})

这篇关于为什么我所有的Firebase云功能都超时了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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