@duvdu-v1/duvdu 1.1.276 → 1.1.278

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1 @@
1
- declare const bullRedis: import("ioredis/built/Redis").default;
2
- export { bullRedis };
1
+ export declare const getBullRedis: () => Promise<import("ioredis/built/Redis").default>;
@@ -1,8 +1,17 @@
1
1
  "use strict";
2
2
  // // bullmq-redis.ts
3
3
  // import IORedis from 'ioredis';
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
4
13
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.bullRedis = void 0;
14
+ exports.getBullRedis = void 0;
6
15
  // const bullRedis = new IORedis({
7
16
  // host: process.env.REDIS_HOST?.split('://')[1]?.split(':')[0] || 'localhost',
8
17
  // port: parseInt(process.env.REDIS_HOST?.split(':').pop() || '6379'),
@@ -17,6 +26,8 @@ exports.bullRedis = void 0;
17
26
  // export { bullRedis };
18
27
  // bullmq-redis.ts
19
28
  const redis_connection_1 = require("./redis-connection");
20
- // Use the existing Redis client from redis-connection.ts
21
- const bullRedis = (0, redis_connection_1.getRedisClient)();
22
- exports.bullRedis = bullRedis;
29
+ // Create a function that returns the Redis client for BullMQ
30
+ const getBullRedis = () => __awaiter(void 0, void 0, void 0, function* () {
31
+ return yield (0, redis_connection_1.getRedisClient)();
32
+ });
33
+ exports.getBullRedis = getBullRedis;
@@ -1,6 +1,6 @@
1
1
  import RedisStore from 'connect-redis';
2
2
  import Redis from 'ioredis';
3
- export declare const getRedisClient: () => Redis;
3
+ export declare const getRedisClient: () => Promise<Redis>;
4
4
  export declare const redisConnection: () => Promise<Redis>;
5
5
  export declare const sessionStore: () => Promise<RedisStore>;
6
6
  export declare const cleanupRedis: () => Promise<void>;
@@ -17,10 +17,11 @@ const connect_redis_1 = __importDefault(require("connect-redis"));
17
17
  const ioredis_1 = __importDefault(require("ioredis"));
18
18
  const data_base_connections_1 = require("../errors/data-base-connections");
19
19
  // Create a Redis cluster or connection pool
20
- const MAX_CLIENTS = 2; // Limited to 2 connections to stay well below the connection limit
20
+ const MAX_CLIENTS = 1; // Single connection per service to minimize total connections
21
21
  let connectionPool = [];
22
22
  let currentConnectionIndex = 0;
23
23
  let activeConnections = 0;
24
+ let isInitializing = false;
24
25
  // Cache the RedisStore instance
25
26
  let redisStoreInstance = null;
26
27
  // Parse Redis connection details
@@ -35,6 +36,7 @@ const getRedisConfig = () => {
35
36
  password,
36
37
  maxRetriesPerRequest: null,
37
38
  enableReadyCheck: false,
39
+ lazyConnect: true, // Don't connect immediately
38
40
  retryStrategy: (times) => {
39
41
  if (times > 3)
40
42
  return null;
@@ -57,7 +59,7 @@ const getClientInfo = (client) => __awaiter(void 0, void 0, void 0, function* ()
57
59
  const startMonitoring = () => {
58
60
  const monitorInterval = 60000; // 1 minute
59
61
  setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
60
- if (connectionPool.length > 0) {
62
+ if (connectionPool.length > 0 && activeConnections > 0) {
61
63
  try {
62
64
  const clientCount = yield getClientInfo(connectionPool[0]);
63
65
  console.log(`[REDIS] Stats: Connected clients: ${clientCount}, Pool size: ${connectionPool.length}, Active: ${activeConnections}`);
@@ -69,8 +71,9 @@ const startMonitoring = () => {
69
71
  }), monitorInterval);
70
72
  };
71
73
  // Initialize the connection pool
72
- const initializePool = () => {
73
- if (connectionPool.length === 0) {
74
+ const initializePool = () => __awaiter(void 0, void 0, void 0, function* () {
75
+ if (connectionPool.length === 0 && !isInitializing) {
76
+ isInitializing = true;
74
77
  const config = getRedisConfig();
75
78
  for (let i = 0; i < MAX_CLIENTS; i++) {
76
79
  const client = new ioredis_1.default(config);
@@ -90,22 +93,27 @@ const initializePool = () => {
90
93
  }
91
94
  // Start monitoring
92
95
  startMonitoring();
96
+ isInitializing = false;
93
97
  }
94
- };
98
+ });
95
99
  // Get a client from the pool using round-robin
96
- const getRedisClient = () => {
100
+ const getRedisClient = () => __awaiter(void 0, void 0, void 0, function* () {
97
101
  if (connectionPool.length === 0) {
98
- initializePool();
102
+ yield initializePool();
99
103
  }
100
- // Round-robin selection
104
+ // Round-robin selection (though with MAX_CLIENTS=1, this just returns the single client)
101
105
  const client = connectionPool[currentConnectionIndex];
102
106
  currentConnectionIndex = (currentConnectionIndex + 1) % connectionPool.length;
107
+ // Ensure the client is connected
108
+ if (client.status !== 'ready' && client.status !== 'connecting') {
109
+ yield client.connect();
110
+ }
103
111
  return client;
104
- };
112
+ });
105
113
  exports.getRedisClient = getRedisClient;
106
114
  const redisConnection = () => __awaiter(void 0, void 0, void 0, function* () {
107
115
  try {
108
- const client = (0, exports.getRedisClient)();
116
+ const client = yield (0, exports.getRedisClient)();
109
117
  return client;
110
118
  }
111
119
  catch (error) {
@@ -119,7 +127,7 @@ const sessionStore = () => __awaiter(void 0, void 0, void 0, function* () {
119
127
  if (redisStoreInstance) {
120
128
  return redisStoreInstance;
121
129
  }
122
- const client = (0, exports.getRedisClient)();
130
+ const client = yield (0, exports.getRedisClient)();
123
131
  redisStoreInstance = new connect_redis_1.default({ client });
124
132
  return redisStoreInstance;
125
133
  });
@@ -36,6 +36,7 @@ export interface ITransaction {
36
36
  status: string;
37
37
  timeStamp: Date;
38
38
  model: string;
39
+ isSubscription: boolean;
39
40
  }
40
41
  export declare const Transaction: import("mongoose").Model<ITransaction, {}, {}, {}, import("mongoose").Document<unknown, {}, ITransaction> & ITransaction & {
41
42
  _id: Types.ObjectId;
@@ -17,4 +17,5 @@ exports.Transaction = (0, mongoose_1.model)(model_names_1.MODELS.transaction, ne
17
17
  status: { type: String, default: TransactionStatus.PENDING },
18
18
  timeStamp: { type: Date, default: Date.now },
19
19
  model: { type: String, default: null },
20
+ isSubscription: { type: Boolean, default: false },
20
21
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duvdu-v1/duvdu",
3
- "version": "1.1.276",
3
+ "version": "1.1.278",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [