diff --git a/src/rdrama/session/SessionManager.ts b/src/rdrama/session/SessionManager.ts index 38f8199..9876178 100644 --- a/src/rdrama/session/SessionManager.ts +++ b/src/rdrama/session/SessionManager.ts @@ -20,13 +20,18 @@ class SessionManager { datastore: "ioredis", clearDatastore: false, clientOptions: { - host: process.env.REDIS_HOST, + host: process.env.REDIS_HOST!, port: Number(process.env.REDIS_PORT), password: process.env.REDIS_PASSWORD || undefined, // Use undefined if no password is set enableOfflineQueue: true }, 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({ @@ -82,13 +87,13 @@ class SessionManager { // Wrap the post method const originalPost = instance.post; instance.post = >(url: string, data?: any, config?: AxiosRequestConfig): Promise => { - return this.limiter.schedule(() => originalPost.apply(instance, [url, data, config])) as Promise; + return this.limiter.schedule({ priority: 1 }, () => originalPost.apply(instance, [url, data, config])) as Promise; }; // Wrap the put method const originalPut = instance.put; instance.put = >(url: string, data?: any, config?: AxiosRequestConfig): Promise => { - return this.limiter.schedule(() => originalPut.apply(instance, [url, data, config])) as Promise; + return this.limiter.schedule({ priority: 1 }, () => originalPut.apply(instance, [url, data, config])) as Promise; }; // Wrap the delete method