首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebase云函数scheduledFunction给出错误:进程已退出,代码为16

Firebase云函数scheduledFunction给出错误:进程已退出,代码为16
EN

Stack Overflow用户
提问于 2021-10-19 08:36:52
回答 1查看 152关注 0票数 1

我正试着在firebase上运行一个预定的云函数。当它运行时,我在日志中看到以下错误:

代码语言:javascript
复制
Error: Process exited with code 16
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:237:22)
    at process.emit (events.js:400:28)
    at process.emit (domain.js:470:12)
    at process.exit (internal/process/per_thread.js:169:15)
    at Object.sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:38:9)
    at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:233:22)
    at process.emit (events.js:400:28)
    at process.emit (domain.js:470:12)
    at processPromiseRejections (internal/process/promises.js:245:33)
    at processTicksAndRejections (internal/process/task_queues.js:96:32) 

下面是我的函数:

代码语言:javascript
复制
exports.scheduledFunction = functions.pubsub
 .schedule("every 5 minutes")
 .onRun((context) => {
   console.log("This will be run every 5 minutes!");
   const tsToMillis = admin.firestore.Timestamp.now().toMillis();
   // const compareDate = new Date(tsToMillis - 24 * 60 * 60 * 1000);
   const compareDate = new Date(tsToMillis - 5 * 60 * 1000);
   admin
     .firestore()
     .collection("properties").where("status", "==", "Reserved")
     .where("reservationDate", "<", compareDate)
     .where("paymentIsDone", "==", false)
     .get()
     .then((querySnapshot) => {
       querySnapshot.forEach((doc) => {
         admin.firestore().collection("properties").doc(doc.id).update({
           agent: "",
           reservedBy: "",
           reservedByPhoneNumber: "",
           reservationDate: null,
           status: "Remaining",
         });
         console.log("canceling reservations");
       });
     });
   return null;
 });

我想取消预订后24小时内(用于测试5分钟)内未完成付款的物业的预订。

这就是我预留房产的方式:

代码语言:javascript
复制
exports.reserveApt = functions.https.onCall((data, context) => {
  if (!context.auth) {
    return {
      result: "failed",
      msg: "you are not authenticated",
    };
  }
  const doc = admin.firestore().collection("properties").doc(data.aptId);
  // get apt
  return doc.get().then((apt) => {
    apt = apt.data();
    // check apt is not already reserved or sold
    //   console.log(apt);
    if (apt.status !== "Remaining") {
      return {
        result: "failed",
        msg: "Appartment is already reserved or sold",
      };
    }
    // reserve apt with username and phone and changes status to reserved
    return doc
      .update({
        agent: data.agent,
        reservedBy: data.reserveeName,
        reservedByPhoneNumber: data.reserveePhone,
        reservationDate: admin.database.ServerValue.TIMESTAMP,
        status: "Reserved",
        paymentIsDone: false,
      })
      .then(() => {
        console.log("apt reserved");
        return {result: "success"};
      });
  });
});

是时间戳有问题还是怎么的?我不明白。

EN

回答 1

Stack Overflow用户

发布于 2021-10-26 14:26:52

您正在使用.where()在相等运算符(==array-contains)和不等运算符(<<=>!=)之间执行复合查询,其中is invalid in Firebase

代码语言:javascript
复制
admin
  .firestore()
  .collection("properties")
  .where("status", "==", "Reserved")  // First query, using equality comparator
  .where("reservationDate", "<", compareDate) // ERROR! You're using inequality operator '<' after '=='

要执行这样的操作,您需要执行create an index;,这可以通过following the error message完成(检查您的Cloud Functions,单击您的函数,单击LOGS选项卡并搜索错误)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69627572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档