Firestore 云功能优先级 [英] Firestore Cloud Functions priority

查看:24
本文介绍了Firestore 云功能优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firestore Cloud Functions 优先级

Firestore Cloud Functions priority

现在我在 Firestore 数据库中部署了两个云函数.

Now I deploy two cloud functions in the Firestore database.

它们由相同的文档更改触发.

They are triggered by the same document changes.

是否可以指定函数的执行顺序或触发顺序?比如我想让updateCommentNum函数先触发,再触发writeUserLog函数.我怎样才能实现这个目标?

Is it possible to specify the execution order of the functions or the trigger sequence? For example, I want to let updateCommentNum function trigger fist, then trigger writeUserLog function. How could I achieve this goal?

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"

}

推荐答案

没有办法表明函数之间的相对优先级.

There is no way to indicate relative priority between functions.

如果您有一个定义的顺序,希望它们被调用,请使用单个 Cloud Function 并从那里调用两个常规函数:

If you have a defined order you want them invoked in, use a single Cloud Function and just call two regular functions from there:

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"
}

这也将减少调用次数,从而降低操作成本.

That will also reduce the number of invocations, and thus reduce the cost of operating them.

这篇关于Firestore 云功能优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆