javascript - Huge difference in time taken to run a Cloud Function for Firebase doing constant kind of work -


i apologize if posting many questions regarding cloud functions on forum. excited project , in process of moving out firebase-queue workers using in app, in beta , available soon, cloud functions 1 one , want make sure not missing anything. have cloud function used generate authentication token stored on database again read app authenticate user. function pretty simple , doesn't contain work may take varying amount of time finish.

  exports.generateauthenticationtoken = functions.database.ref('/tasks/authentication/{taskid}')   .onwrite(event => {     const tasksnapshot = event.data     if(!tasksnapshot.exists()) {       return     }     const task = tasksnapshot.val()      const uid = task.uid      // make sure user app user     return ref.child('users').child(uid).once('value').then((snapshot) => {       if(!snapshot.exists()) {         console.error('unable authenticate user: invalid uid: ', uid)         return ref.child('taskresults/' + event.params.taskid).set({           category: 'authentication',           status: 'failure',           error: 'invalid uid',         })       } else {         // generate token using          return admin.auth().createcustomtoken(uid).then((token) => {           return ref.child('taskresults/' + event.params.taskid).set({             category: 'authentication',             status: 'success',             result: {               authtoken: token             }           })         })       }     }).then(() => {       ref.child('/tasks/authentication/' + event.params.taskid).remove()     })   }) 

on firebase functions console, in logs section, see logs invocations of functions finish in less 10 ms , take long 4000 ms. wanted ask under circumstances run time cloud function doing constant kind of vary much. particular worker kind of critical app because user has wait authenticated able use app , 4 secs + time taken read token , authenticate makes long.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -