Nick: rate limit fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { RateLimiterRedis } from "rate-limiter-flexible";
|
||||
import * as redis from "redis";
|
||||
import { RateLimiterMode } from "../../src/types";
|
||||
|
||||
const MAX_REQUESTS_PER_MINUTE_PREVIEW = 5;
|
||||
const MAX_CRAWLS_PER_MINUTE_STARTER = 2;
|
||||
@@ -8,6 +9,9 @@ const MAX_CRAWLS_PER_MINUTE_SCALE = 20;
|
||||
|
||||
const MAX_REQUESTS_PER_MINUTE_ACCOUNT = 20;
|
||||
|
||||
const MAX_REQUESTS_PER_MINUTE_CRAWL_STATUS = 120;
|
||||
|
||||
|
||||
|
||||
|
||||
export const redisClient = redis.createClient({
|
||||
@@ -29,6 +33,13 @@ export const serverRateLimiter = new RateLimiterRedis({
|
||||
duration: 60, // Duration in seconds
|
||||
});
|
||||
|
||||
export const crawlStatusRateLimiter = new RateLimiterRedis({
|
||||
storeClient: redisClient,
|
||||
keyPrefix: "middleware",
|
||||
points: MAX_REQUESTS_PER_MINUTE_CRAWL_STATUS,
|
||||
duration: 60, // Duration in seconds
|
||||
});
|
||||
|
||||
|
||||
export function crawlRateLimit(plan: string){
|
||||
if(plan === "standard"){
|
||||
@@ -56,9 +67,13 @@ export function crawlRateLimit(plan: string){
|
||||
}
|
||||
|
||||
|
||||
export function getRateLimiter(preview: boolean){
|
||||
if(preview){
|
||||
|
||||
|
||||
export function getRateLimiter(mode: RateLimiterMode){
|
||||
if(mode === RateLimiterMode.Preview){
|
||||
return previewRateLimiter;
|
||||
}else if(mode === RateLimiterMode.CrawlStatus){
|
||||
return crawlStatusRateLimiter;
|
||||
}else{
|
||||
return serverRateLimiter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user