The question might sound a little weird but I am not sure how to handle this specific issue.
I have a requests than does a few things and sends a response back to the client. In this specific requests i am also doing something after the response is sent back to do some backround stuff. The issue is lying inside this piece of logic / functionality since it requests a third party public API that has a rate limit. Let's say i send 20 requests/s to this endpoint.
10 requests will be processed by the third party public API and processed correctly, but the last 10 requests will not be processed and will return a rate limit error.
My question is - How can I change this logic / endpoint to support my demands. Any feedback and suggestions is much appreciated.
// endpoint /get-data/
await doAlotOfLogicHere();
setTimeout(() => {
// Do something after 1 seconds
// This specific action can only take 10 requests / second
controller.doSomething(req,res)
}, 1000);
// Send response to client
res.status(200).send(data);
controller.doSomething()
exports.doSomething = (req,res) => {
await sendDataToPublicAPI();
}
Your problem is a little big vague... Let me suggest something, though.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.