Firebase云函数在日志中始终超时
我正在使用此链接中的代码: 我总是在云函数的日志中获取超时,下面是一个代码:Firebase云函数在日志中始终超时,firebase,firebase-cloud-messaging,google-cloud-functions,Firebase,Firebase Cloud Messaging,Google Cloud Functions,我正在使用此链接中的代码: 我总是在云函数的日志中获取超时,下面是一个代码: exports.sendPatrola = functions.database.ref('/test/tmp') .onUpdate((change, context) => { const original = change.after.val(); var payload = { data: { id: String(original.id), x: String(original.x), y: Str
exports.sendPatrola = functions.database.ref('/test/tmp')
.onUpdate((change, context) => {
const original = change.after.val();
var payload = {
data: {
id: String(original.id),
x: String(original.x),
y: String(original.y),
dat: String(original.dat)
}
};
var options = {
priority: 'high',
contentAvailable: true,
timeToLive: 60 * 1
};
let tokens = []; // All Device tokens to send a notification to.
// Get the list of device tokens.
return admin.database().ref('keys').once('value').then((allTokens) => {
if (allTokens.val()) {
// Listing all tokens.
tokens = Object.keys(allTokens.val());
// Send notifications to all tokens.
return admin.messaging().sendToDevice(tokens, payload, options);
}
return {results: []};
}).then((response) => {
return cleanupTokens(response, tokens);
}).then(() => {
console.log('Notifications have been sent and tokens cleaned up.');
return null;
});
}
错误消息是:函数执行耗时60002毫秒,状态为“超时”
这里出了什么问题?请尝试这种方式,函数
cleanupTokens
应该返回一个承诺:
exports.sendPatrola = functions.database.ref('/test/tmp').onUpdate((change, context) => {
const original = change.after.val();
var payload = {
data: {
id: String(original.id),
x: String(original.x),
y: String(original.y),
dat: String(original.dat)
}
};
var options = {
priority: 'high',
contentAvailable: true,
timeToLive: 60 * 1
};
let tokens = [];
return admin.database().ref('keys').once('value').then((allTokens) => {
if (allTokens.val()) {
tokens = Object.keys(allTokens.val());
return admin.messaging().sendToDevice(tokens, payload, options);
} else {
const result = [];
return result;
}
}).then((response) => {
return cleanupTokens(response, tokens);
}).then(() => {
console.log('Notifications have been sent and tokens cleaned up.');
return null;
});
});
您正在使用哪个版本的firebase函数?看看这篇文章:看看你是否在2.0.0I使用2.0,这是firebase的问题。谢谢迈克尔!您现在可以安装v2.0.1来解决此问题。是的,现在已通过2.0.1解决了此问题:)