node.js - Firebase cloud functions inconsistent with bulk updates -




i have firebase cloud function in calling external api end point this.

const functions = require('firebase-functions'); var admin = require("firebase-admin"); admin.initializeapp(functions.config().firebase); var request = require('request'); var moment = require('moment'); var rp = require('request-promise');  var db = admin.database();  exports.oncheckin = functions.database.ref('/news/{newsid}/{entryid}')       .oncreate(event => {         console.log("event triggered");         var eventsnapshot = event.data.val();         request.post({               url: 'http://mycustomurl/endpoint/',               form: {                 data: eventsnapshot.data              }             }, function(error, response, body){                  console.log(response);              });          }) 

i using blaze plan , working fine. problem when creating bulk data (around 50 100 entries) http request @ custom url not working properly.one or 2 http request being skipped.

i have debugged custom server , found out not receiving missing requests firebase. have checked cloud function logs , can find every event correctly being triggered.

what problem? doing wrong ?

you're not returning value function. means cloud functions assumes function done work after last statement has run. since you're making asynchronous http call in function, calls may not have completed yet. unfortunately you're not telling cloud functions fact have outstanding call, may kill function @ time after return.

the solution return promise resolves after http request has completed. since you're including request-promise simple:

exports.oncheckin = functions.database.ref('/news/{newsid}/{entryid}') .oncreate(event => {   console.log("event triggered");   var eventsnapshot = event.data.val();   return rp.post({       url: 'http://mycustomurl/endpoint/',       form: {         data: eventsnapshot.data       }   }); }) 

this common problem developers new javascript, or javascript , firebase, , covered in:





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -