title: How to invoke other Cloud Firebase Functions from a Cloud Function
body: <p>Let's say I have a <a href="https://firebase.google.com/docs/functions/" rel="noreferrer">Cloud Firebase Function</a> - called by a cron job - that produces 30+ tasks every time it's invoked.</p>
  
  <p>These tasks are quite slow (5 - 6 second each in average) and I can't process them directly in the original because it would time out.</p>
  
  <p>So, the solution would be invoking another "worker" function, once per task, to complete the tasks independently and write the results in a database. So far I can think of three strategies:</p>
  
  <ol>
  <li><p>Pubsub messages. That would be amazing, but it seems that <a href="https://firebase.google.com/docs/reference/functions/functions.pubsub" rel="noreferrer">you can only listen on pubsub messages from within a Cloud Function</a>, not create one. Resorting to external solutions, like having a GAE instance, is not an option for me.</p></li>
  <li><p>Call the worker http-triggered Firebase Cloud Function from the first one. That won't work, I think, because I would need to wait for a response from the all the invoked worker functions, after they finish and <code>send</code>, and my original Function would time out.</p></li>
  <li><p>Append tasks to a real time database list, then have a worker function triggered by each database change. The worker has to delete the task from the queue afterwards. That would probably work, but it feels there are a lot of moving parts for a simple problem. For example, what if the worker throws? Another cron to "clean" the db would be needed etc.</p></li>
  </ol>
  
  <p>Another solution that comes to mind is <a href="https://github.com/firebase/firebase-queue" rel="noreferrer">firebase-queue</a>, but its README explicitly states:</p>
  
  <blockquote>
    <p>"There may continue to be specific use-cases for firebase-queue,
    however if you're looking for a general purpose, scalable queueing
    system for Firebase then it is likely that building on top of Google
    Cloud Functions for Firebase is the ideal route"</p>
  </blockquote>
  
  <p>It's not officially supported and they're practically saying that we should use Functions instead (which is what I'm trying to do). I'm a bit nervous on using in prod a library that might be abandoned tomorrow (if it's not already) and would like to avoid going down that route.</p>