Hi I’m working on push notifications in javascript. The final code will probably go in either a Parse or node.js server somewhere. I realized that for tasks like this, it would be nice to be able to follow the pattern that php/mysql typically uses for sending emails:
begin database transaction
save email details in database
send email
end database transaction
Or to clean up automatically in case of unexpected errors or exceptions:
with database transaction
{
save email details in database
send email
}
That way if anything goes wrong, the user can always try again by resubmitting the form or whatever.
So my question is, is there a way to do something similar in Firebase? I realize there are transactions in the SDK but I’m trying to do this purely through the REST API. I stumbled onto this:
http://stackoverflow.com/a/23068147
I’m thinking that this may be possible by using a node kind of like a mutex or semaphore, by setting a flag to indicate the server is busy, then clearing it when the server is done. There are problems with this approach though if the connection drops. The mutex would need to be reset after a timeout period. I would prefer to do it in a lockless (atomic) manner.
One way that might work is to set up a queue node for the server, and only allow adding children if the update_counter in the request is equal to the old update_counter + 1. So users could submit jobs on the work queue and the server would watch for them and do what’s requested. This would probably require getting javascript to only run one task at a time somehow, even if users are making multiple simultaneous requests. Otherwise we’d have multiple readers and be back to figuring out how to isolate their transactions again. The nice thing though is that I could take advantage of the SDK’s transaction functions when the users post jobs to the queue. The only catch there is that the users are technically untrustworthy, so this should have to work safely whether they use transactions or not, the way the stack overflow answer above works.
Anyway, it helped to write this but I’m worried that I’m making it overly complicated. Anyone know if there’s a way to implement begin/end transaction on a node or two?
Thanks for any help you can provide,
Zack Morris