dt-common-device 13.10.4 → 13.10.5

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.
@@ -20,7 +20,8 @@ export declare enum Resource {
20
20
  ACCESS_BLE = "accessBle",
21
21
  EMERGENCY_CODE = "emergencyCode",
22
22
  EMERGENCY_RFID = "emergencyRfid",
23
- EMERGENCY_BLE = "emergencyBle"
23
+ EMERGENCY_BLE = "emergencyBle",
24
+ SERVER = "server"
24
25
  }
25
26
  export interface IAuditProperties {
26
27
  resource: Resource;
@@ -24,4 +24,5 @@ var Resource;
24
24
  Resource["EMERGENCY_CODE"] = "emergencyCode";
25
25
  Resource["EMERGENCY_RFID"] = "emergencyRfid";
26
26
  Resource["EMERGENCY_BLE"] = "emergencyBle";
27
+ Resource["SERVER"] = "server";
27
28
  })(Resource || (exports.Resource = Resource = {}));
@@ -99,7 +99,7 @@ let HybridHttpQueue = (() => {
99
99
  (0, config_1.getConfig)().LOGGER.info(`Request queued: ${method} ${url} -> ${provider} [${connectionId}]. Job ID: ${jobId}, Delay: ${delay}ms`);
100
100
  // Wait for job completion and return result
101
101
  // Simple: delay + windowMs + HTTP buffer timeout
102
- return queueUtils_1.QueueUtils.waitForJobCompletion(jobId, queueKey, delay, windowMs);
102
+ return queueUtils_1.QueueUtils.waitForJobCompletion(jobId, queueKey, delay, windowMs, this.queues);
103
103
  }
104
104
  async processHttpRequest(job) {
105
105
  // Log immediately when worker picks up the job
@@ -147,7 +147,7 @@ let HybridHttpQueue = (() => {
147
147
  return this.handleRequest(url, method, httpCallOption);
148
148
  }
149
149
  async handleRequest(url, method, options) {
150
- const { connectionId, provider, microservice } = jobUtils_1.JobUtils.extractConnectionDetails(options);
150
+ const { connectionId, provider } = jobUtils_1.JobUtils.extractConnectionDetails(options);
151
151
  // Check rate limit first
152
152
  const allowed = await rateLimit_utils_1.RateLimitUtils.isRateLimitAllowed(connectionId, provider, this.rateLimitConfigs);
153
153
  if (allowed) {
@@ -8,5 +8,5 @@ export declare class QueueUtils {
8
8
  static waitForRateLimitExpiry(connectionId: string, provider: string, rateLimitConfigs: Map<string, IRateLimitConfig>): Promise<void>;
9
9
  static executeHttpRequest(url: string, method: string, options: HttpCallOption, connectionId: string, provider: string): Promise<any>;
10
10
  static addJobToQueue(queueKey: string, jobData: any, delay: number, queues: Map<string, any>): Promise<string>;
11
- static waitForJobCompletion(jobId: string, queueKey: string, jobDelay?: number, windowMs?: number): Promise<any>;
11
+ static waitForJobCompletion(jobId: string, queueKey: string, jobDelay: number | undefined, windowMs: number | undefined, queues: Map<string, any>): Promise<any>;
12
12
  }
@@ -208,16 +208,15 @@ class QueueUtils {
208
208
  }
209
209
  return job.id;
210
210
  }
211
- static async waitForJobCompletion(jobId, queueKey, jobDelay = 0, windowMs = 60000) {
211
+ static async waitForJobCompletion(jobId, queueKey, jobDelay = 0, windowMs = 60000, queues) {
212
212
  // Simple: delay (wait) + windowMs (execute) + HTTP timeout buffer
213
213
  const httpTimeout = 60000;
214
214
  const totalTimeout = jobDelay + windowMs + httpTimeout;
215
215
  console.log(`[${new Date().toISOString()}] [waitForJobCompletion] Waiting for job ${jobId} - delay: ${jobDelay}ms, timeout: ${totalTimeout}ms`);
216
216
  const startTime = Date.now();
217
- const { Queue } = require("bullmq");
218
- const queue = new Queue(queueKey, {
219
- connection: (0, redis_1.getRedisClient)(),
220
- });
217
+ // Reuse the existing queue instance — never create a new Queue per call
218
+ // (each new Queue duplicates the Redis connection, causing a connection leak)
219
+ const queue = this.getOrCreateQueue(queueKey, queues);
221
220
  return new Promise(async (resolve, reject) => {
222
221
  const checkInterval = setInterval(async () => {
223
222
  try {
@@ -226,7 +225,6 @@ class QueueUtils {
226
225
  const elapsed = Date.now() - startTime;
227
226
  if (elapsed > totalTimeout) {
228
227
  clearInterval(checkInterval);
229
- await queue.close();
230
228
  return reject(new Error(`Job ${jobId} not found and timeout exceeded`));
231
229
  }
232
230
  return; // Job not found yet, keep checking
@@ -236,26 +234,22 @@ class QueueUtils {
236
234
  console.log(`[${new Date().toISOString()}] [waitForJobCompletion] Job ${jobId} completed`);
237
235
  clearInterval(checkInterval);
238
236
  const result = job.returnvalue;
239
- await queue.close();
240
237
  return resolve(result);
241
238
  }
242
239
  if (state === "failed") {
243
240
  console.log(`[${new Date().toISOString()}] [waitForJobCompletion] Job ${jobId} failed: ${job.failedReason}`);
244
241
  clearInterval(checkInterval);
245
- await queue.close();
246
242
  return reject(new Error(job.failedReason || "Job failed"));
247
243
  }
248
244
  }
249
245
  catch (error) {
250
246
  clearInterval(checkInterval);
251
- await queue.close();
252
247
  reject(error);
253
248
  }
254
249
  }, 500); // Check every 500ms
255
250
  // Timeout
256
251
  setTimeout(() => {
257
252
  clearInterval(checkInterval);
258
- queue.close();
259
253
  reject(new Error(`Request timeout: Maximum wait time exceeded (${totalTimeout}ms). Job delay was ${jobDelay}ms.`));
260
254
  }, totalTimeout);
261
255
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dt-common-device",
3
- "version": "13.10.4",
3
+ "version": "13.10.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [