【发布时间】:2021-11-01 20:16:24
【问题描述】:
我使用示例 Firebase 文档创建了以下云函数:
export const subscribeToTopic = functions.https.onRequest((request, response) => {
const topic = "weeklySurvey";
const registrationTokens = [
"c3UXI...ktYZ" // token Truncated here for readability
];
return admin.messaging().subscribeToTopic(registrationTokens, topic)
.then((response) => {
console.log("Successfully subscribed to topic:", response);
//Update: Tried adding next line to avoid timeout error
return response.status(200).send("Subscribed!");
//But this returns a predeploy error:
//Property 'status' does not exist on type 'MessagingTopicManagementResponse'.
})
.catch((error) => {
console.log("Error subscribing to topic:", error);
return response.status(500).send("Something went wrong");
});
});
函数执行成功没有错误:
subscribeToTopic
Successfully subscribed to topic: { successCount: 1, failureCount: 0, errors: [] }
...然后在 60 秒时超时:
subscribeToTopic
Function execution took 60002 ms, finished with status: 'timeout'
我是否缺少在subscribeToTopic 完成后终止函数的代码?
Firebase 文档代码参考MessagingTopicManagementResponse,或许暗示我这里需要更多?
admin.messaging().subscribeToTopic(registrationTokens, topic)
.then((response) => {
// See the MessagingTopicManagementResponse reference documentation
// for the contents of response.
console.log('Successfully subscribed to topic:', response);
})
【问题讨论】:
标签: node.js firebase google-cloud-functions firebase-cloud-messaging