我正在尝试运行一个云函数并更改数据库上的一个值,但每次我返回一个promise时,无论有没有'firebase-admin‘模块,函数都会在60秒后超时。
下面是我的代码:
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!'); // this never triggers
});
}
});发布于 2017-07-17 20:46:07
if (eventSnapshot.changed() && isDisconnected) {
console.log('is disconnected true');`
return admin.database.ref('/...')
.set({ disconnection: false }, err => {
if(!err) // No error
{ console.log("Set Updated"); }
});设置方法有一个回调,它将err作为对象传递,您可以使用err来获取操作状态。
发布于 2017-07-18 04:10:24
https://stackoverflow.com/questions/43262296
复制相似问题