I try to run a cloud function and change the value in the database, but every time I return a promise with or without firebase-admin, the function expires after 60 seconds.
Here is my code:
var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.handleDisconnection = functions.database.ref('/pages/{pageId}/listeners/disconnection')
.onWrite(event => {
const eventSnapshot = event.data;
const isDisconnected = eventSnapshot.val();
const pageId = event.params.pageId;
console.log('there is a new disconnection on page ' + pageId + ', isDisconnected: ' + isDisconnected);
if (eventSnapshot.changed() && isDisconnected) {
console.log('is disconnected true');
return admin.database().ref('/pages/'+pageId+'/listeners/disconnection').set({ disconnection: false }).then(() => {
console.log('Write succeeded!');
});
}
});
source
share