部署超时后第一次调用Firebase云函数

部署超时后第一次调用Firebase云函数,firebase,google-cloud-functions,Firebase,Google Cloud Functions,我为firebase部署了一个HTTP云函数。但是,在部署之后,第一次调用返回超时错误代码。我正在使用Android的volley库来调用HTTP函数。 随后的调用似乎工作得很好 我所做的:我觉得这个问题可能是冷启动时间的问题,但是我尝试将超时时间从代码增加到180秒。但我还是遇到了同样的问题 代码:显示问题的完整云功能 const runtimeOptsActivateApp = { timeoutSeconds: 180, memory: '128MB' } exports.act

我为firebase部署了一个HTTP云函数。但是,在部署之后,第一次调用返回超时错误代码。我正在使用Android的volley库来调用HTTP函数。 随后的调用似乎工作得很好

我所做的:我觉得这个问题可能是冷启动时间的问题,但是我尝试将超时时间从代码增加到180秒。但我还是遇到了同样的问题

代码:显示问题的完整云功能

const runtimeOptsActivateApp = {
  timeoutSeconds: 180,
  memory: '128MB'
}

exports.activateApp = functions.runWith(runtimeOptsActivateApp).https.onRequest((req, res) => {
  const pin = req.query.pin;
  const id_token = req.query.auth;
  let docId;
  let uid;
  let email;

  // idToken comes from the client app
  admin.auth().verifyIdToken(id_token)
  .then(decodedToken => {
    uid = decodedToken.uid;
    email = decodedToken.email;

    return activationPinsRef
      .where("pin", "==", pin)
      .get()

  })
  .then(querySnapshot=>{
    if(querySnapshot.empty){
      return Promise.reject(new Error("Activation pin does not exist..."))
    }

    return activationPinsRef
      .where("pin", "==", pin)
      .where("is_blocked", "==", false)
      .get()

  })
  .then(querySnapshot=>{
    if(querySnapshot.empty){
      return Promise.reject(new Error("User has been blocked..."))
    }

    return activationPinsRef
      .where("pin", "==", pin)
      .where("is_blocked", "==", false)
      .where("has_activated", "==", false)
      .get()

  })
  .then(querySnapshot=>{
    if(querySnapshot.empty){
      console.log("User has activated, He may be trying to reactivate, verify his activation status in users document!")
      return usersRef
        .doc(uid)
        .get()
    }

    console.log("User is a trying to activate for the first time!")
    querySnapshot.forEach(documentSnapshot => {
      docId = documentSnapshot.id;
    })
    return activationPinsRef
      .doc(docId)
      .update({
        "has_activated": true,
        "uid_activated": uid,
        "time_activated": Date.now()
      })

  })
  .then(result => {

    if(result instanceof admin.firestore.DocumentSnapshot){
      var is_activated = result.data().is_activated;
      if(is_activated){
        console.log('Reactivation successful!!!');
        return res.status(200).send({
          "status": "success",
          "is_reactivation": true
        })
      }
      return Promise.reject(new Error("User is_activated field is false!"))
    }

    usersRef
      .doc(uid)
      .update({
        is_activated:true
      })

    return res.status(200).send({
      "status": "success",
      "is_reactivation": false
    })
  })
  .catch(error => {
    console.log(error)
    return res.status(401).end()
  })

});

您好,您应该在问题中添加云函数的全部代码。如果看不到代码,几乎不可能帮助您。你好,雷诺,我刚刚用相关代码更新了这个问题。