Firestore Cloud Functions 优先级
现在我在 Firestore 数据库中部署两个云函数。
它们是由相同的文档更改触发的。
是否可以指定函数的执行顺序或触发顺序?例如,我想让updateCommentNum函数触发拳头,然后触发writeUserLog函数。我怎样才能实现这个目标?
exports.updateCommentNum = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) =>
{
//update the comment numbers in the post/{postId}/
}
exports.writeUserLog = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) =>
{
//write the comment name,text,ID,timestamp etc. in the collection "commentlog"
}
最佳答案
无法指示函数之间的相对优先级。
如果您希望按照定义的顺序调用它们,请使用单个云函数,然后从那里调用两个常规函数:
exports.onCommentWritten = functions.firestore
.document('post/{postId}/comments/{commentsID}')
.onWrite((change, context) => {
return Promise.all([
updateCommentNum,
writeUserLog
])
})
function updateCommentNum(change, context) {
//update the comment numbers in the post/{postId}/
}
function writeUserLog(change, context) {
//write the comment name,text,ID,timestamp etc. in the collection "commentlog"
}
这也将减少调用次数,从而降低运行它们的成本。
关于javascript - Firestore Cloud Functions 优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52450997/