Khalifa Alkhatri
Khalifa Alkhatri

Reputation: 294

Firebase Function : How to trigger Functions in order

I would like to know if the firebase function trigger support calling by order in other word calling one then next one ! for example Im waiting my pizza to buy but in front of me 15 people so I have to wait people then I buy pizza .

this Could help ?! :

var Queue = require('firebase-queue');
var admin = require('firebase-admin');

var serviceAccount = require('path/to/serviceAccountCredentials.json');
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: '<your-database-url>'
});

var ref = admin.database().ref('queue');
var queue = new Queue(ref, function(data, progress, resolve, reject) {
  // Read and process task data
  console.log(data);

  // Do some work
  progress(50);

  // Finish the task asynchronously
  setTimeout(function() {
    resolve();
  }, 1000);
});

Upvotes: 0

Views: 175

Answers (1)

Zeenath S N
Zeenath S N

Reputation: 1170

According to the Firebase documentation, one of the limitations is that the order in which the Cloud Functions are triggered is not guaranteed. Also a single event may cause multiple Cloud Functions invocations.

A detailed explanation of a work around can be found in the How to deal with Firebase trigger function execution order. Here a community member’s workaround is to store a admin.database.ServerValue.TIMESTAMP with the list add and verify in the results calculator that it produced results for the latest timestamp. If not, it tries again.

Upvotes: 2

Related Questions