从 firestore 和 Firebase 函数中获取超时
Fetching from firestore and Firebase functions timeout
我有一个简单的功能,我正在模拟器上进行本地测试。
exports.sendNotification = functions.https.onRequest(() => {
firebase
.firestore()
.collection("Users")
.get()
.then((snapshot) => {
snapshot.docs.forEach((doc) => {
console.log(doc.id, doc.data());
});
});
});
当我执行该函数时,它工作正常,但在我收到此消息后不久:
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)
我的期望是函数会正常结束,因为它在函数结束时,这条消息是说我需要做一些事情来表明函数已经完成吗?我是否需要更改某些内容,尤其是在投入生产时?
您必须 terminate a HTTP function 发回响应,否则它将 运行 直到超时。尝试像这样重构您的代码:
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()) })
});
});
我有一个简单的功能,我正在模拟器上进行本地测试。
exports.sendNotification = functions.https.onRequest(() => {
firebase
.firestore()
.collection("Users")
.get()
.then((snapshot) => {
snapshot.docs.forEach((doc) => {
console.log(doc.id, doc.data());
});
});
});
当我执行该函数时,它工作正常,但在我收到此消息后不久:
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)
我的期望是函数会正常结束,因为它在函数结束时,这条消息是说我需要做一些事情来表明函数已经完成吗?我是否需要更改某些内容,尤其是在投入生产时?
您必须 terminate a HTTP function 发回响应,否则它将 运行 直到超时。尝试像这样重构您的代码:
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()) })
});
});