简体   繁体   中英

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.

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.

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 ).

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. The part about command-response starts here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM