rdrama reservoir with OVERFLOW_PRIORITY highwater strategy

master
j 2024-03-31 00:20:33 -04:00
parent de052304d0
commit f11ed3cb81
1 changed files with 8 additions and 3 deletions

View File

@ -26,7 +26,12 @@ class SessionManager {
enableOfflineQueue: true enableOfflineQueue: true
}, },
maxConcurrent: 1, // Maximum number of concurrent requests maxConcurrent: 1, // Maximum number of concurrent requests
minTime: 1000 // Minimum time between dispatches of requests in milliseconds minTime: 1000, // Minimum time between dispatches of requests in milliseconds
reservoir: 41, // Initial reservoir value for the first hour
reservoirRefreshAmount: 41, // Reservoir value to reset to every hour
reservoirRefreshInterval: 60 * 60 * 1000, // Interval to reset the reservoir (1 hour in milliseconds)
highWater: 5, // Maximum number of queued jobs.
strategy: Bottleneck.strategy.OVERFLOW_PRIORITY // Strategy to drop the oldest jobs in the queue when highWater is reached
}); });
this.axiosInstance = axios.create({ this.axiosInstance = axios.create({
@ -82,13 +87,13 @@ class SessionManager {
// Wrap the post method // Wrap the post method
const originalPost = instance.post; const originalPost = instance.post;
instance.post = <T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R> => { instance.post = <T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R> => {
return this.limiter.schedule(() => originalPost.apply(instance, [url, data, config])) as Promise<R>; return this.limiter.schedule({ priority: 1 }, () => originalPost.apply(instance, [url, data, config])) as Promise<R>;
}; };
// Wrap the put method // Wrap the put method
const originalPut = instance.put; const originalPut = instance.put;
instance.put = <T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R> => { instance.put = <T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R> => {
return this.limiter.schedule(() => originalPut.apply(instance, [url, data, config])) as Promise<R>; return this.limiter.schedule({ priority: 1 }, () => originalPut.apply(instance, [url, data, config])) as Promise<R>;
}; };
// Wrap the delete method // Wrap the delete method