【发布时间】:2021-12-06 04:30:25
【问题描述】:
我正在尝试在 firebase 上运行计划的云功能。我在运行时在日志中看到此错误:
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)
这是我的功能:
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 分钟)内取消对未完成付款的住宿的预订。
这是我保留房产的方式:
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"};
});
});
});
是时间戳的问题还是什么?我不明白。
【问题讨论】:
标签: node.js firebase cron google-cloud-functions timestamp