I've made one cloud function to do the following:
- Get order id's filtert on day before today (around 400 id's) one time at night.
- For each id get detailed information from source.
- For each detailed information get extra information from target.
- Send to target as invoice.
My problem is in step 2. The rate limit is 14 request per minute. So i was thinking to create an Pub/Sub between 1 and 2. Create a subscription function that pulls messages from the topic. Processes 14 of them and ack those messages, then resolve the promise. But this leave me with questions:
- Is this the right flow?
- How do i schedule step 2?
- if i get a 429 response i wait for 1 minute (this will be billed)
- let step 2 run every 1 minute to not get the 429 response code? (this will run a long time of the day when there are no messages.
- instead of pulling let the pub/sub trigger the function, check the response code -> if 429 then wait for 1 minute to proces. But then my question: Will it invoke one instance of the cloud function or multiple?
I hope someone can share some thoughts. I'm new to cloud functions and async programming. My hole function works as expected with a limit of 5 orders. Just later on i came acros this rate limit (i know, stupid me).