[英]How to abort creation into firebase realtime database from a cloud function?
I'm creating an application that uses two step object creation into firebase realtime database. 我正在创建一个使用两步对象创建到Firebase实时数据库中的应用程序。
What I want is that on a cloud function that catches onCreate event, if some rules are not complete, then the create action be stopped. 我想要的是在捕获onCreate事件的云函数上,如果某些规则不完整,则将停止create操作。
Is there a way to do that? 有没有办法做到这一点? Or I need to remove the node instead of reject the creation? 还是我需要删除节点而不是拒绝创建?
Thank you! 谢谢!
There currently is no way to reschedule a trigger. 当前无法重新安排触发器的时间。 So indeed, you'll either have to create a new node or trigger a re-check in some other way, eg a regular cron trigger to clean up the previously unhandled nodes ( blog , video ). 因此,实际上,您要么必须创建一个新节点,要么以其他方式触发重新检查,例如,定期的cron触发器以清理以前未处理的节点( blog , video )。
You might want to consider a command-response model for database writes. 您可能要考虑数据库写入的命令响应模型。 Instead of writing directly into the database and expecting that a function cancel the write, push a "command" object into the database that describes what you want to do, at a different location, and have a function respond to that command to determine what should actually be done. 与其直接写到数据库中并期望某个函数取消写操作,不如将一个“命令”对象推入数据库,该对象描述您要在其他位置执行的操作,并让一个函数响应该命令以确定应该执行的操作实际完成。 Your function can then determine whether or not to commit a final write if the conditions are OK. 然后,如果条件确定,您的函数可以确定是否提交最终写入。
I gave a talk at Google I/O 2017 that outlines this strategy with respect to a multi-player turn based game that intercepts all move requests to determine if they're valid before committing them to the game. 我在2017年Google I / O大会上的演讲中概述了基于多人回合游戏的这一策略,该游戏在将所有移动请求提交到游戏之前会拦截所有移动请求以确定它们是否有效。 The part about command-response starts here . 关于命令响应的部分从此处开始 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.