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 badges1 Answer
Reset to default 11A 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