简体   繁体   English

从 firestore 获取和 Firebase 函数超时

[英]Fetching from firestore and Firebase functions timeout

I have a simple function that I am testing locally on the emulator.我有一个简单的 function,我正在模拟器上进行本地测试。

    exports.sendNotification = functions.https.onRequest(() => {
  firebase
    .firestore()
    .collection("Users")
    .get()
    .then((snapshot) => {
      snapshot.docs.forEach((doc) => {
        console.log(doc.id, doc.data());
      });
    });
});

When I execute the function, it works fine, but shortly after I get this message:当我执行 function 时,它工作正常,但在我收到此消息后不久:

     functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
>  C:\Users\myusername\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:618
>              throw new Error("Function timed out.");
>              ^
>
>  Error: Function timed out.
>      at Timeout._onTimeout (C:\Users\myusername\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:618:19)
>      at listOnTimeout (node:internal/timers:557:17)
>      at processTimers (node:internal/timers:500:7)

my expectation was that the function would just end normally since its at the end of the function, is this message saying that I need to do something to indicate the function has finished?我的期望是 function 会正常结束,因为它在 function 结束时,这条消息是说我需要做些什么来表明 function 已经结束吗? Do I need to change something especially when pushing to production?我是否需要更改某些内容,尤其是在投入生产时?

You must terminate a HTTP function by sending back a response otherwise it'll run until it times out.您必须通过发回响应来 终止 HTTP function否则它将一直运行直到超时。 Try refactoring your code like this:尝试像这样重构您的代码:

exports.sendNotification = functions.https.onRequest((req, res) => {
  // add req, res in functions parameters             ^^^
  return firebase
    .firestore()
    .collection("Users")
    .get()
    .then((snapshot) => {
      snapshot.docs.forEach((doc) => {
        console.log(doc.id, doc.data());
      });
      // Return response
      return res.json({ data: snapshot.docs.map(d => d.data()) })
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nextjs getStaticPaths 不从 firebase firestore 获取数据 - Nextjs getStaticPaths not fetching data from firebase firestore 使用 flutter 从 firebase Firestore 获取数据 - fetching data from firebase firestore using flutter 与 firebase 云函数中的 firebase firestore 交互 - Interacting with firebase firestore from firebase cloud functions 正在获取 Firebase Firestore 引用 - Fetching Firebase Firestore References Cloud Functions for Firebase 超时 - Cloud Functions for Firebase timeout 使用 admin sdk 和 Firebase 云函数从 Firestore 检索对象数组 - Retrieving an array of objects from Firestore with the admin sdk and Firebase cloud functions Firebase Firestore 使用 ID 引用获取数据然后获取引用 - Firebase Firestore fetching data with an ID reference then fetching the reference 我在使用 flutter 从 firestore firebase 获取图像时遇到问题 - i am facing a problem in fetching image from firestore firebase using flutter React Native Firebase Firestore 数据未正确获取 - React Native Firebase Firestore data not fetching properly 从firestore(firebase)获取数据时出现错误。 我正在使用本机反应 - I am getting an error while fetching data from firestore(firebase). I am using react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM