Firebase云功能始终在日志中超时

时间:2018-07-25 18:11:42

标签: firebase firebase-cloud-messaging google-cloud-functions

我正在使用以下链接中的代码:https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#9

并且我总是在日志中超时以获取云功能,这是一个代码:

HashRouter

错误消息是:函数执行耗时60002 ms,状态为:“超时”

这是怎么了?

1 个答案:

答案 0 :(得分:0)

请尝试这种方式,函数cleanupTokens应该返回一个promise:

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;
  });
});