最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase Function always finished with timeout - Stack Overflow

programmeradmin3浏览0评论

i am using firebase function for creating notifications with cloud messaging. But i am always getting this Error:

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

but the notification works.

This is the code i am using in index.js:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();


exports.SendNotification = functions.https.onRequest((req, res) => {  

  var payload = {
      notification: {
         title: "this is a test",
         body: req.rawBody.toString('utf8')
      }
  }

  return admin.messaging().sendToTopic("all", payload);

});

Do i have to implement a response? When, how do i do that?

J3nsis

i am using firebase function for creating notifications with cloud messaging. But i am always getting this Error:

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

but the notification works.

This is the code i am using in index.js:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();


exports.SendNotification = functions.https.onRequest((req, res) => {  

  var payload = {
      notification: {
         title: "this is a test",
         body: req.rawBody.toString('utf8')
      }
  }

  return admin.messaging().sendToTopic("all", payload);

});

Do i have to implement a response? When, how do i do that?

J3nsis

Share Improve this question asked Nov 29, 2018 at 17:24 Jens BeckerJens Becker 1,6811 gold badge9 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

A HTTPS-triggered Cloud Function ends when it sends a response to its caller. Since your code never sends a response, the code keep running until its configured timeout (which is 1 minute by default).

To properly terminate the function when it's done, send a result back after the FCM call pletes:

admin.messaging().sendToTopic("all", payload).then(() => {
  res.status(200).send("ok");
}).catch((err) => {
  res.status(500).send(err);
});

I remend reading this section in the docs:

  • Terminate HTTP Functions
发布评论

评论列表(0)

  1. 暂无评论