node.js - How to prevent multiple reaction by Google Cloud VM instances for one event from Firebase database? -
the problem: dosomething() function, invoked twice (by each running vm instance).
how can react each event 1 vm instance?
node.js script @ google cloud platform:
function listenfornotificationrequests() { var requests = ref.child('some_node'); requests.on('child_added', function(requestsnapshot) { var request = requestsnapshot.val(); dosomething( request.type, function() { requestsnapshot.ref.remove(); }); }, function(error) { console.error(error); }); };
firebase-queue solves problem, @frank's comment pointed.
multiple queue workers can initialized on multiple machines , firebase-queue ensure 1 worker processing single queue task @ time.
Comments
Post a Comment