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
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 completes:
I recommend reading this section in the docs: