Hi, Is there a way to prevent two API requests to the same URL at the same time?
Yes of course. By using any queue management you can prevent it.
1 Like
Thank you! Is there any queue management in strapi? Or can u give me an example of how I could build one?
There is no queue in strapi as far i know. you can use bull queue GitHub - OptimalBits/bull: Premium Queue package for handling distributed jobs and messages in NodeJS.</ti. Read the documents.
here is a example of a queue
const myRateLimitedQueue = new Queue(‘rateLimited’, {
redis: {
host: '127.0.0.1',
port: 6379
},
limiter: {
max: 1,
duration: 10
}
})
const data = {
header : "header"
}
await myRateLimitedQueue.add(data);
async function getCheck() {
return new Promise((resolve, reject) => {
return myRateLimitedQueue.process(async (job) => {
resolve("check");
});
});
}
var condition= await getCheck();