Node.js 谷歌云发布/订阅功能在查询firestore时给出“请求的快照版本太旧”
我有一个gcloud pub/sub函数,可以对集合执行简单的查询。在08年10月之前,它运转良好。现在我看到请求的快照版本太旧的错误消息 我用相同的代码创建了一个HTTP函数,并手动运行,它运行得非常好 以下是函数:Node.js 谷歌云发布/订阅功能在查询firestore时给出“请求的快照版本太旧”,node.js,firebase,google-cloud-firestore,google-cloud-functions,google-cloud-pubsub,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,Google Cloud Pubsub,我有一个gcloud pub/sub函数,可以对集合执行简单的查询。在08年10月之前,它运转良好。现在我看到请求的快照版本太旧的错误消息 我用相同的代码创建了一个HTTP函数,并手动运行,它运行得非常好 以下是函数: // 0 3 * * * - at 03:00 AM every day exports.GenerateRankings = functions.pubsub.schedule('0 3 * * *') .onRun((context) => {
// 0 3 * * * - at 03:00 AM every day
exports.GenerateRankings = functions.pubsub.schedule('0 3 * * *')
.onRun((context) => {
console.log("GenerateRankings Task started")
const playersCollection = admin.firestore().collection('players')
playersCollection.orderBy("Coin", "desc").get()
.then((qs) => {
console.log("Fetching Players by Coin")
// some staff
return true
})
.catch((error) => {
console.error("Error fetching players", error)
return false
})
})
下面是错误堆栈:
9 FAILED_PRECONDITION: The requested snapshot version is too old.
at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:327:49)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:305:181)
at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:124:78
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Caused by: Error
at Query._get (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:1466:23)
at Query.get (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:1455:21)
at /workspace/index.js:22:47
at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:130:23)
at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:198:28
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 9,
details: 'The requested snapshot version is too old.',
metadata: Metadata { internalRepr: Map {}, options: {} }
}
我知道还有一个问题没有回答
与此类似。我在发布/订阅功能方面遇到了这个问题
谢谢你的帮助。如果有人遇到这个问题,我会回答我自己的问题 经过大量的阅读和测试,我注意到我的日志中有一个警告,比如函数返回了未定义的、预期的承诺或值。因为我在函数中返回了一个承诺,所以我没有注意到这一点 在我的函数上添加一个返回值修复了我的警告,并且我的函数已经成功运行了5天
return exports.GenerateRankings = functions.pubsub.schedule('0 3 * * *') ...
如果有人面临这个问题,我会回答自己的问题 经过大量的阅读和测试,我注意到我的日志中有一个警告,比如函数返回了未定义的、预期的承诺或值。因为我在函数中返回了一个承诺,所以我没有注意到这一点 在我的函数上添加一个返回值修复了我的警告,并且我的函数已经成功运行了5天
return exports.GenerateRankings = functions.pubsub.schedule('0 3 * * *') ...
我遇到了同样的问题,在我的例子中,代码如下,并且返回了这个问题中提到的错误
const userSnapshots = await this.firestore.collection('Users').where('archive', '==', false).get();
const users = userSnapshots.docs
users.map(async (user) => {
//code to update user documents
});
然后,我将代码更改为以下代码,它在不返回本期中提到的错误的情况下工作
const userSnapshots = await this.firestore.collection('Users').where('archive', '==', false).get();
const users = userSnapshots.docs
const markPromises = users.map(async (user) => {
//code to update user documents
});
await Promise.all(markPromises);
我不知道这是这个问题的正确答案,但这对我来说很有效。我遇到了同样的问题,在我的例子中,代码如下,并且返回了这个问题中提到的错误
const userSnapshots = await this.firestore.collection('Users').where('archive', '==', false).get();
const users = userSnapshots.docs
users.map(async (user) => {
//code to update user documents
});
然后,我将代码更改为以下代码,它在不返回本期中提到的错误的情况下工作
const userSnapshots = await this.firestore.collection('Users').where('archive', '==', false).get();
const users = userSnapshots.docs
const markPromises = users.map(async (user) => {
//code to update user documents
});
await Promise.all(markPromises);
我不知道这是这个问题的正确答案,但这对我来说很有效。我花了几个小时试图在pubsub中运行一个操作列表,然后我决定尝试下面的代码,结果成功了
this.firestore.collection('Users').where('archive', '==', false).get().then(snap=>{
// Code Here
});
我花了几个小时试图在pubsub中运行一系列操作,然后我决定尝试下面的代码,它成功了
this.firestore.collection('Users').where('archive', '==', false).get().then(snap=>{
// Code Here
});
这是在每个函数触发器上发生的还是偶发的错误?每次我发现这一错误时都会发生,它引用了此错误,并指出如果订阅中的积压时间太长,并且生成的快照将在不到1小时内过期,则返回FAILED_Premission。不确定这是否有帮助,但这是我找到的唯一一条关于这一点的信息。我想说,你最好用谷歌的打开一个bug,这样他们就可以对你的特殊情况进行故障排除。谢谢,@RafaelLemos。我已经解决了这个问题,请检查我的答案。这是在每个函数触发器上发生的还是偶发的错误?每次我发现这个错误时都会发生,它引用了这个错误,并说如果订阅中的积压工作太旧,并且生成的快照将在不到1小时内过期,则返回失败的\u前提条件。不确定这是否有帮助,但这是我找到的唯一一条关于这一点的信息。我想说,你最好用谷歌的打开一个bug,这样他们就可以对你的特殊情况进行故障排除。谢谢,@RafaelLemos。我已经解决了这个问题,请检查我的答案。