Hello, we are working on a project and encountering the RateLimitError while using the Async Events API. It seems we add more jobs (events) to the queue within a minute than the allowed limit of 500 events per minute. To address this, we are trying to implement logic to throttle the rate at which events are pushed to the queue.
Is there any “proper” solution to it? How would you handle such scenario? we are thinking of this solution taking in account the doc stating “The total number of events pushed per minute exceeds the defined limits. To overcome this, retry adding events after a minute.”
async function pushEventToQueue(payload) {
try {
await queue.push(payload);
} catch (error) {
if (error instanceof RateLimitError) {
console.warn("Rate limit exceeded. Retrying after a minute...");
// Implement retry logic after a minute
await new Promise(resolve => setTimeout(resolve, 60000)); // Wait for 1 minute
await pushEventToQueue(payload); // Retry pushing the event
} else {
console.error("Error pushing event to queue:", error);
// Handle other errors as needed
}
}
}
Is it generally a good approach? isn’t those 60 seconds too much to wait? We will be glad for any opinion