dt-common-device 13.10.5 → 13.10.6
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,10 +1,21 @@
|
|
|
1
|
-
import { IAuditProperties } from "./IAuditProperties";
|
|
1
|
+
import { IAuditProperties, PartialAuditProperties } from "./IAuditProperties";
|
|
2
2
|
/**
|
|
3
3
|
* Publishes an audit event. Failures are logged and swallowed so callers can
|
|
4
4
|
* fire-and-forget without causing unhandled promise rejections when the audit
|
|
5
5
|
* pipeline returns 5xx or times out (see e.g. Sentry DT-PMS-C).
|
|
6
|
+
* USE FOR PROPERTY LEVEL AUDITS
|
|
6
7
|
*/
|
|
7
8
|
export declare function pushAudit(data: {
|
|
8
9
|
auditType: string;
|
|
9
10
|
auditData: IAuditProperties;
|
|
10
11
|
}): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Publishes an audit event. Failures are logged and swallowed so callers can
|
|
14
|
+
* fire-and-forget without causing unhandled promise rejections when the audit
|
|
15
|
+
* pipeline returns 5xx or times out (see e.g. Sentry DT-PMS-C).
|
|
16
|
+
* USE FOR SYSTEM LEVEL AUDITS (If Property ID is not available)
|
|
17
|
+
*/
|
|
18
|
+
export declare function pushSystemAudit(data: {
|
|
19
|
+
auditType: string;
|
|
20
|
+
auditData: PartialAuditProperties;
|
|
21
|
+
}): Promise<void>;
|
package/dist/audit/PushAudit.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.pushAudit = pushAudit;
|
|
7
|
+
exports.pushSystemAudit = pushSystemAudit;
|
|
7
8
|
const dt_audit_library_1 = require("dt-audit-library");
|
|
8
9
|
const config_1 = require("../config/config");
|
|
9
10
|
const AuditUtils_1 = require("./AuditUtils");
|
|
@@ -12,6 +13,7 @@ const typedi_1 = __importDefault(require("typedi"));
|
|
|
12
13
|
* Publishes an audit event. Failures are logged and swallowed so callers can
|
|
13
14
|
* fire-and-forget without causing unhandled promise rejections when the audit
|
|
14
15
|
* pipeline returns 5xx or times out (see e.g. Sentry DT-PMS-C).
|
|
16
|
+
* USE FOR PROPERTY LEVEL AUDITS
|
|
15
17
|
*/
|
|
16
18
|
async function pushAudit(data) {
|
|
17
19
|
try {
|
|
@@ -33,3 +35,28 @@ async function pushAudit(data) {
|
|
|
33
35
|
: { auditType: data.auditType });
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Publishes an audit event. Failures are logged and swallowed so callers can
|
|
40
|
+
* fire-and-forget without causing unhandled promise rejections when the audit
|
|
41
|
+
* pipeline returns 5xx or times out (see e.g. Sentry DT-PMS-C).
|
|
42
|
+
* USE FOR SYSTEM LEVEL AUDITS (If Property ID is not available)
|
|
43
|
+
*/
|
|
44
|
+
async function pushSystemAudit(data) {
|
|
45
|
+
try {
|
|
46
|
+
await (0, dt_audit_library_1.publishAudit)({
|
|
47
|
+
eventType: data.auditType,
|
|
48
|
+
properties: {
|
|
49
|
+
...data.auditData,
|
|
50
|
+
timestamp: new Date().toISOString(),
|
|
51
|
+
env_type: process.env.NODE_ENV,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
const status = err?.response?.status;
|
|
57
|
+
const code = err?.code;
|
|
58
|
+
(0, config_1.getLogger)().error(`pushSystemAudit failed for ${data.auditType}: ${err?.message ?? err}`, status != null || code != null
|
|
59
|
+
? { auditType: data.auditType, status, code }
|
|
60
|
+
: { auditType: data.auditType });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -35,6 +35,8 @@ class QueueUtils {
|
|
|
35
35
|
console.log(`[${new Date().toISOString()}] [getOrCreateWorker] Existing worker running status: ${isRunning}`);
|
|
36
36
|
if (!isRunning) {
|
|
37
37
|
console.log(`[${new Date().toISOString()}] [getOrCreateWorker] Worker not running, closing and recreating...`);
|
|
38
|
+
// Stale worker detected — surface at WARN level with count context
|
|
39
|
+
(0, config_1.getConfig)().LOGGER.warn(`Stale worker for queue ${queueKey} (not running), recreating. Active workers before recreate: ${workers.size}`);
|
|
38
40
|
try {
|
|
39
41
|
existingWorker.close();
|
|
40
42
|
}
|
|
@@ -116,7 +118,8 @@ class QueueUtils {
|
|
|
116
118
|
});
|
|
117
119
|
workers.set(queueKey, worker);
|
|
118
120
|
console.log(`[${new Date().toISOString()}] [getOrCreateWorker] Worker initialized and stored for queue: ${queueKey}`);
|
|
119
|
-
|
|
121
|
+
// Log total active workers — a growing count here signals a connection-proliferation leak
|
|
122
|
+
(0, config_1.getConfig)().LOGGER.info(`Worker initialized for queue: ${queueKey} (total active workers: ${workers.size})`);
|
|
120
123
|
}
|
|
121
124
|
static async waitForRateLimitExpiry(connectionId, provider, rateLimitConfigs) {
|
|
122
125
|
const key = `rate_limit:${provider}:${connectionId}`;
|
|
@@ -202,6 +205,10 @@ class QueueUtils {
|
|
|
202
205
|
queue.getActiveCount(),
|
|
203
206
|
]);
|
|
204
207
|
console.log(`[${new Date().toISOString()}] [addJobToQueue] Queue state - QueueKey: ${queueKey}, Waiting: ${waiting}, Delayed: ${delayed}, Active: ${active}`);
|
|
208
|
+
// Warn via structured logger when backlog is building — correlates with heap stats
|
|
209
|
+
if (waiting + delayed > 1) {
|
|
210
|
+
(0, config_1.getConfig)().LOGGER.warn(`Queue backlog [${queueKey}]: waiting=${waiting} delayed=${delayed} active=${active}`);
|
|
211
|
+
}
|
|
205
212
|
}
|
|
206
213
|
catch (e) {
|
|
207
214
|
// Ignore errors getting queue state
|
|
@@ -250,6 +257,9 @@ class QueueUtils {
|
|
|
250
257
|
// Timeout
|
|
251
258
|
setTimeout(() => {
|
|
252
259
|
clearInterval(checkInterval);
|
|
260
|
+
// Log via structured logger before rejecting so the timeout is visible in
|
|
261
|
+
// CloudWatch alongside the periodic heap stats — correlates queue stalls with memory pressure.
|
|
262
|
+
(0, config_1.getConfig)().LOGGER.error(`Job ${jobId} timed out after ${totalTimeout}ms [${queueKey}] (jobDelay=${jobDelay}ms)`);
|
|
253
263
|
reject(new Error(`Request timeout: Maximum wait time exceeded (${totalTimeout}ms). Job delay was ${jobDelay}ms.`));
|
|
254
264
|
}, totalTimeout);
|
|
255
265
|
});
|