【发布时间】:2021-09-14 17:57:48
【问题描述】:
我目前在处理某些仅在触发另一个实例后才写入的云功能时遇到问题。
我的云函数代码如下,由 pubsub 事件触发。
if (jsonData.Event == "TEST") {
var msg = jsonData.Value;
var timeOfReception = new Date();
//changer l'occupation courante
docRef
.get()
.then(function (doc) {
if (doc.exists) {
docRef.update({
LastGesture: msg,
}).then(function() {
console.log("Write completed")
}).catch(function(error) {
console.error("Write failed: "+error)
});
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
})
.catch(function (error) {
console.log("Error getting document:", error);
});
}
这是来自同一云功能的日志:
2021-07-02 15:44:17.869 EDTpubsubToFireStoregsn141ejhe1b Function execution started
Default
2021-07-02 15:44:17.874 EDTpubsubToFireStoregsn141ejhe1b {Date: 2000/00/00-00:00:00, DeviceID: TSA00001, Event: TEST, Location: MAISON, Value: PRESENT, Version: 1.0, tableName: GestureTest}
Debug
2021-07-02 15:44:17.875 EDTpubsubToFireStoregsn141ejhe1b Function execution took 7 ms, finished with status: 'ok'
Default
2021-07-02 15:44:18.532 EDTpubsubToFireStoregsn141ejhe1b Write completed
Debug
2021-07-02 16:04:27.466 EDTpubsubToFireStore2o6osfooylkj Function execution started
Default
2021-07-02 16:04:27.513 EDTpubsubToFireStore2o6osfooylkj {Date: 2000/00/00-00:00:00, DeviceID: TSA00001, Event: TEST, Location: MAISON, Value: ABSENT, Version: 1.0, tableName: GestureTest}
Debug
2021-07-02 16:04:27.548 EDTpubsubToFireStore2o6osfooylkj Function execution took 85 ms, finished with status: 'ok'
Debug
2021-07-02 16:05:40.824 EDTpubsubToFireStore2o6ozvzxeri1 Function execution started
Default
2021-07-02 16:05:41.347 EDTpubsubToFireStore2o6ozvzxeri1 {Date: 2000/00/00-00:00:00, DeviceID: TSA00001, Event: TEST, Location: MAISON, Value: PRESENT, Version: 1.0, tableName: GestureTest}
Debug
2021-07-02 16:05:41.351 EDTpubsubToFireStore2o6ozvzxeri1 Function execution took 528 ms, finished with status: 'ok'
Default
2021-07-02 16:06:07.130 EDTpubsubToFireStore2o6ozvzxeri1 Write completed
Default
2021-07-02 16:06:07.830 EDTpubsubToFireStore2o6ozvzxeri1 Write completed
如您所见,15:44:17 的函数完美运行:函数被触发并执行写操作。但是,16:04:27 的函数直到 16:05:41 的函数被触发才写入,正如它所显示的那样,这两个函数几乎同时写入。
我不确定如何解释这种行为,因为我还是云功能的新手。如果有什么可以为我指明正确的方向,我将不胜感激:)。如果需要,我可以提供更多详细信息。谢谢!
【问题讨论】:
标签: node.js google-cloud-firestore google-cloud-functions