How to Implement a Sequential Task Queue in Firebase Without Parallel Processing Issues?

178 Views Asked by At

I'm new to Firebase and trying to set up a task queue. My objective is to read requests with a 'pending' status from a datastore queue, send an HTTP request to an external third-party server, and then update the request status to 'ready'. The external server has a response time of around 5-10 seconds and does not support parallel calls, so I have to ensure that only one request is being processed at a time.

I tried the following approaches:

Triggered Function: I attempted to trigger a Cloud Function when a new record is added to the queue repository. I expected this to work, but it led to parallel processing, which is not supported by the external server.

Scheduled Job: Another option I considered was running a scheduled job. However, Firebase's minimum scheduling time is one minute, which is too long for my use case where each request takes 5-10 seconds to process.

Cloud Tasks: I also looked into Cloud Tasks, but I don't see how it would be applicable since I'm dealing with an external third-party service.

I was expecting to find a method to process each request one at a time while adhering to the timing requirements.

1

There are 1 best solutions below

0
Doug Stevenson On

You can use Cloud Tasks to set up a queue that's limited to 1 concurrent dispatch. You provide the code to deal with the third party service as an HTTP endpoint that Cloud Tasks will invoke for each request in the queue.