@devrev/ts-adaas 1.11.1-beta.17 → 1.11.1-beta.18
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.
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.interfaces.d.ts +4 -1
- package/dist/logger/logger.interfaces.d.ts.map +1 -1
- package/dist/logger/logger.js +15 -2
- package/dist/logger/logger.test.js +10 -9
- package/dist/types/workers.d.ts +1 -0
- package/dist/types/workers.d.ts.map +1 -1
- package/dist/workers/create-worker.d.ts.map +1 -1
- package/dist/workers/create-worker.js +2 -7
- package/dist/workers/spawn.d.ts +2 -2
- package/dist/workers/spawn.d.ts.map +1 -1
- package/dist/workers/spawn.js +25 -14
- package/dist/workers/worker.js +5 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,OAAO,EAAE,UAAU,EAAyC,MAAM,OAAO,CAAC;AAG1E,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EAEtB,QAAQ,EAER,cAAc,EACf,MAAM,qBAAqB,CAAC;AAE7B,qBAAa,MAAO,SAAQ,OAAO;IACjC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,OAAO,CAAC,CAAuB;IACvC,OAAO,CAAC,IAAI,CAAa;gBAEb,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,sBAAsB;IAUtD,OAAO,CAAC,aAAa;IAYrB,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;IA0BpC,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI7B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAGzC;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,cAAc,CAyB5E;AACD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE1D;AAED,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,YAK5C,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAwBzE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RawAxiosResponseHeaders } from 'axios';
|
|
2
|
-
import { AirdropEvent } from '../types/extraction';
|
|
2
|
+
import { AirdropEvent, EventContext } from '../types/extraction';
|
|
3
3
|
import { WorkerAdapterOptions } from '../types/workers';
|
|
4
4
|
export interface LoggerFactoryInterface {
|
|
5
5
|
event: AirdropEvent;
|
|
@@ -36,4 +36,7 @@ export interface AxiosErrorResponse {
|
|
|
36
36
|
code?: string;
|
|
37
37
|
message?: string;
|
|
38
38
|
}
|
|
39
|
+
export interface LoggerTags extends EventContext {
|
|
40
|
+
sdk_version: string;
|
|
41
|
+
}
|
|
39
42
|
//# sourceMappingURL=logger.interfaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.interfaces.d.ts","sourceRoot":"","sources":["../../src/logger/logger.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.interfaces.d.ts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 -6,20 +6,23 @@ exports.formatAxiosError = formatAxiosError;
|
|
|
6
6
|
exports.serializeAxiosError = serializeAxiosError;
|
|
7
7
|
const node_console_1 = require("node:console");
|
|
8
8
|
const node_util_1 = require("node:util");
|
|
9
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
9
10
|
const axios_1 = require("axios");
|
|
11
|
+
const constants_1 = require("../common/constants");
|
|
12
|
+
const workers_1 = require("../types/workers");
|
|
10
13
|
const logger_interfaces_1 = require("./logger.interfaces");
|
|
11
14
|
class Logger extends node_console_1.Console {
|
|
12
15
|
constructor({ event, options }) {
|
|
13
16
|
super(process.stdout, process.stderr);
|
|
14
17
|
this.originalConsole = console;
|
|
15
18
|
this.options = options;
|
|
16
|
-
this.tags = Object.assign(Object.assign({}, event.payload.event_context), {
|
|
19
|
+
this.tags = Object.assign(Object.assign({}, event.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION });
|
|
17
20
|
}
|
|
18
21
|
valueToString(value) {
|
|
19
22
|
if (typeof value === 'string') {
|
|
20
23
|
return value;
|
|
21
24
|
}
|
|
22
|
-
// Use Node.js built-in inspect for everything including errors
|
|
25
|
+
// Use Node.js built-in inspect for everything including errors, functions, symbols, circular refs
|
|
23
26
|
return (0, node_util_1.inspect)(value, {
|
|
24
27
|
compact: false,
|
|
25
28
|
depth: Infinity,
|
|
@@ -27,6 +30,16 @@ class Logger extends node_console_1.Console {
|
|
|
27
30
|
}
|
|
28
31
|
logFn(args, level) {
|
|
29
32
|
var _a;
|
|
33
|
+
// Worker thread sends the log to the main thread to log it
|
|
34
|
+
if (!node_worker_threads_1.isMainThread && node_worker_threads_1.parentPort) {
|
|
35
|
+
const sanitizedArgs = args.map((arg) => this.valueToString(arg));
|
|
36
|
+
node_worker_threads_1.parentPort.postMessage({
|
|
37
|
+
subject: workers_1.WorkerMessageSubject.WorkerMessageLog,
|
|
38
|
+
payload: { args: sanitizedArgs, level },
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
// Main thread logs the log normally
|
|
30
43
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.isLocalDevelopment) {
|
|
31
44
|
this.originalConsole[level](...args);
|
|
32
45
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_util_1 = require("node:util");
|
|
4
|
+
const constants_1 = require("../common/constants");
|
|
4
5
|
const test_helpers_1 = require("../tests/test-helpers");
|
|
5
6
|
const extraction_1 = require("../types/extraction");
|
|
6
7
|
const logger_1 = require("./logger");
|
|
@@ -46,12 +47,12 @@ describe(logger_1.Logger.name, () => {
|
|
|
46
47
|
jest.restoreAllMocks();
|
|
47
48
|
});
|
|
48
49
|
describe('constructor', () => {
|
|
49
|
-
it('should initialize logger with event context and
|
|
50
|
+
it('should initialize logger with event context and sdk_version', () => {
|
|
50
51
|
const logger = new logger_1.Logger({ event: mockEvent, options: mockOptions });
|
|
51
52
|
// Access private property for testing
|
|
52
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
54
|
const tags = logger.tags;
|
|
54
|
-
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), {
|
|
55
|
+
expect(tags).toEqual(Object.assign(Object.assign({}, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION }));
|
|
55
56
|
});
|
|
56
57
|
});
|
|
57
58
|
describe('production logging', () => {
|
|
@@ -63,7 +64,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
63
64
|
it('should log single string message without backslashes', () => {
|
|
64
65
|
const message = 'Worker is online. Started processing the task.';
|
|
65
66
|
logger.info(message);
|
|
66
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), {
|
|
67
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
67
68
|
});
|
|
68
69
|
it('should log single object message with JSON stringify', () => {
|
|
69
70
|
const data = { id: 123, name: 'test' };
|
|
@@ -72,7 +73,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
72
73
|
compact: false,
|
|
73
74
|
depth: Infinity,
|
|
74
75
|
});
|
|
75
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), {
|
|
76
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: expectedMessage }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
76
77
|
});
|
|
77
78
|
it('should log multiple arguments joined with space', () => {
|
|
78
79
|
const text = 'Successfully fetched';
|
|
@@ -82,7 +83,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
82
83
|
compact: false,
|
|
83
84
|
depth: Infinity,
|
|
84
85
|
});
|
|
85
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), {
|
|
86
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text} ${expectedDataMessage}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
86
87
|
});
|
|
87
88
|
it('should handle mixed string and object arguments', () => {
|
|
88
89
|
const text1 = 'Processing';
|
|
@@ -93,7 +94,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
93
94
|
compact: false,
|
|
94
95
|
depth: Infinity,
|
|
95
96
|
});
|
|
96
|
-
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), {
|
|
97
|
+
expect(mockConsoleInfo).toHaveBeenCalledWith(JSON.stringify(Object.assign(Object.assign({ message: `${text1} ${expectedDataMessage} ${text2}` }, mockEvent.payload.event_context), { sdk_version: constants_1.LIBRARY_VERSION })));
|
|
97
98
|
});
|
|
98
99
|
});
|
|
99
100
|
describe('local development logging', () => {
|
|
@@ -144,7 +145,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
144
145
|
const callArgs = mockConsoleInfo.mock.calls[0][0];
|
|
145
146
|
const logObject = JSON.parse(callArgs);
|
|
146
147
|
expect(logObject.message).toBe('');
|
|
147
|
-
expect(logObject.
|
|
148
|
+
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
148
149
|
expect(logObject.request_id).toBe(mockEvent.payload.event_context.request_id);
|
|
149
150
|
});
|
|
150
151
|
it('[edge] should handle null and undefined values', () => {
|
|
@@ -154,7 +155,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
154
155
|
const logObject = JSON.parse(callArgs);
|
|
155
156
|
// inspect shows 'null' and 'undefined' as strings
|
|
156
157
|
expect(logObject.message).toBe('test null undefined');
|
|
157
|
-
expect(logObject.
|
|
158
|
+
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
158
159
|
});
|
|
159
160
|
it('[edge] should handle complex nested objects', () => {
|
|
160
161
|
const complexObject = {
|
|
@@ -175,7 +176,7 @@ describe(logger_1.Logger.name, () => {
|
|
|
175
176
|
depth: Infinity,
|
|
176
177
|
});
|
|
177
178
|
expect(logObject.message).toBe(expectedMessage);
|
|
178
|
-
expect(logObject.
|
|
179
|
+
expect(logObject.sdk_version).toBe(constants_1.LIBRARY_VERSION);
|
|
179
180
|
expect(typeof logObject.callback_url).toBe('string');
|
|
180
181
|
});
|
|
181
182
|
});
|
package/dist/types/workers.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../../src/types/workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAA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AAY,WAAW;IACrB,aAAa,YAAY;IACzB,YAAY,WAAW;IACvB,WAAW,UAAU;IACrB,UAAU,SAAS;CACpB;AAED;;GAEG;AACH,oBAAY,oBAAoB;IAC9B,oBAAoB,SAAS;IAC7B,iBAAiB,SAAS;IAC1B,gBAAgB,QAAQ;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,oBAAoB,CAAC,oBAAoB,CAAC;IACnD,OAAO,EAAE;QACP,SAAS,EAAE,kBAAkB,GAAG,eAAe,CAAC;KACjD,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,oBAAoB,CAAC,iBAAiB,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,cAAc;IACxC,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,cAAc,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,YAAY,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/workers/create-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-worker.d.ts","sourceRoot":"","sources":["../../src/workers/create-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAE3D,iBAAe,YAAY,CAAC,cAAc,EACxC,UAAU,EAAE,UAAU,CAAC,cAAc,CAAC,GACrC,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -2,26 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createWorker = createWorker;
|
|
4
4
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
5
|
-
const logger_1 = require("../logger/logger");
|
|
6
5
|
const workers_1 = require("../types/workers");
|
|
7
6
|
async function createWorker(workerData) {
|
|
8
7
|
return new Promise((resolve, reject) => {
|
|
9
8
|
if (node_worker_threads_1.isMainThread) {
|
|
10
|
-
const logger = new logger_1.Logger({
|
|
11
|
-
event: workerData.event,
|
|
12
|
-
options: workerData.options,
|
|
13
|
-
});
|
|
14
9
|
const workerFile = __dirname + '/worker.js';
|
|
15
10
|
const worker = new node_worker_threads_1.Worker(workerFile, {
|
|
16
11
|
workerData,
|
|
17
12
|
});
|
|
18
13
|
worker.on(workers_1.WorkerEvent.WorkerError, (error) => {
|
|
19
|
-
|
|
14
|
+
console.error('Worker error', error);
|
|
20
15
|
reject(error);
|
|
21
16
|
});
|
|
22
17
|
worker.on(workers_1.WorkerEvent.WorkerOnline, () => {
|
|
23
18
|
resolve(worker);
|
|
24
|
-
|
|
19
|
+
console.info('Worker is online. Started processing the task with event type: ' +
|
|
25
20
|
workerData.event.payload.event_type +
|
|
26
21
|
'.');
|
|
27
22
|
});
|
package/dist/workers/spawn.d.ts
CHANGED
|
@@ -19,9 +19,9 @@ export declare class Spawn {
|
|
|
19
19
|
private softTimeoutTimer;
|
|
20
20
|
private hardTimeoutTimer;
|
|
21
21
|
private memoryMonitoringInterval;
|
|
22
|
-
private logger;
|
|
23
22
|
private resolve;
|
|
24
|
-
|
|
23
|
+
private originalConsole;
|
|
24
|
+
constructor({ event, worker, options, resolve, originalConsole, }: SpawnInterface);
|
|
25
25
|
private clearTimeouts;
|
|
26
26
|
private exitFromMainThread;
|
|
27
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAWA,OAAO,EAEL,qBAAqB,EACrB,cAAc,EAGf,MAAM,kBAAkB,CAAC;AA4D1B;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,cAAc,EAAE,EAC1C,KAAK,EACL,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,OAAO,GACR,EAAE,qBAAqB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/workers/spawn.ts"],"names":[],"mappings":"AAWA,OAAO,EAEL,qBAAqB,EACrB,cAAc,EAGf,MAAM,kBAAkB,CAAC;AA4D1B;;;;;;;;;;GAUG;AACH,wBAAsB,KAAK,CAAC,cAAc,EAAE,EAC1C,KAAK,EACL,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,OAAO,GACR,EAAE,qBAAqB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA4EvD;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,oBAAoB,CAAkC;IAC9D,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,gBAAgB,CAA4C;IACpE,OAAO,CAAC,wBAAwB,CAA6C;IAC7E,OAAO,CAAC,OAAO,CAA4C;IAC3D,OAAO,CAAC,eAAe,CAAU;gBAErB,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,eAAe,GAChB,EAAE,cAAc;IA8FjB,OAAO,CAAC,aAAa;YAYP,kBAAkB;CAgCjC"}
|
package/dist/workers/spawn.js
CHANGED
|
@@ -72,13 +72,15 @@ function getWorkerPath({ event, connectorWorkerPath, }) {
|
|
|
72
72
|
* @returns {Promise<Spawn>} - A new instance of Spawn class
|
|
73
73
|
*/
|
|
74
74
|
async function spawn({ event, initialState, workerPath, initialDomainMapping, options, }) {
|
|
75
|
-
const
|
|
75
|
+
const originalConsole = console;
|
|
76
|
+
// eslint-disable-next-line no-global-assign
|
|
77
|
+
console = new logger_1.Logger({ event, options });
|
|
76
78
|
const script = getWorkerPath({
|
|
77
79
|
event,
|
|
78
80
|
connectorWorkerPath: workerPath,
|
|
79
81
|
});
|
|
80
82
|
if (options === null || options === void 0 ? void 0 : options.isLocalDevelopment) {
|
|
81
|
-
|
|
83
|
+
console.warn('WARN: isLocalDevelopment is deprecated. Please use the -- local flag instead.');
|
|
82
84
|
}
|
|
83
85
|
// read the command line arguments to check if the local flag is passed
|
|
84
86
|
const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).argv;
|
|
@@ -100,16 +102,19 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
100
102
|
worker,
|
|
101
103
|
options,
|
|
102
104
|
resolve,
|
|
105
|
+
originalConsole,
|
|
103
106
|
});
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
catch (error) {
|
|
107
|
-
|
|
110
|
+
console.error('Worker error while processing task', error);
|
|
111
|
+
// eslint-disable-next-line no-global-assign
|
|
112
|
+
console = originalConsole;
|
|
108
113
|
return Promise.reject(error);
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
else {
|
|
112
|
-
|
|
117
|
+
console.error('Script was not found for event type: ' + event.payload.event_type + '.');
|
|
113
118
|
try {
|
|
114
119
|
await (0, control_protocol_1.emit)({
|
|
115
120
|
event,
|
|
@@ -124,24 +129,28 @@ async function spawn({ event, initialState, workerPath, initialDomainMapping, op
|
|
|
124
129
|
});
|
|
125
130
|
}
|
|
126
131
|
catch (error) {
|
|
127
|
-
|
|
132
|
+
console.error('Error while emitting event.', (0, logger_1.serializeError)(error));
|
|
128
133
|
return Promise.reject(error);
|
|
129
134
|
}
|
|
135
|
+
finally {
|
|
136
|
+
// eslint-disable-next-line no-global-assign
|
|
137
|
+
console = originalConsole;
|
|
138
|
+
}
|
|
130
139
|
}
|
|
131
140
|
}
|
|
132
141
|
class Spawn {
|
|
133
|
-
constructor({ event, worker, options, resolve }) {
|
|
142
|
+
constructor({ event, worker, options, resolve, originalConsole, }) {
|
|
134
143
|
this.defaultLambdaTimeout = constants_1.DEFAULT_LAMBDA_TIMEOUT;
|
|
135
144
|
this.alreadyEmitted = false;
|
|
136
145
|
this.event = event;
|
|
137
|
-
this.logger = new logger_1.Logger({ event, options });
|
|
138
146
|
this.lambdaTimeout = (options === null || options === void 0 ? void 0 : options.timeout)
|
|
139
147
|
? Math.min(options.timeout, this.defaultLambdaTimeout)
|
|
140
148
|
: this.defaultLambdaTimeout;
|
|
141
149
|
this.resolve = resolve;
|
|
150
|
+
this.originalConsole = originalConsole;
|
|
142
151
|
// If soft timeout is reached, send a message to the worker to gracefully exit.
|
|
143
152
|
this.softTimeoutTimer = setTimeout(() => void (async () => {
|
|
144
|
-
|
|
153
|
+
console.log('SOFT TIMEOUT: Sending a message to the worker to gracefully exit.');
|
|
145
154
|
if (worker) {
|
|
146
155
|
worker.postMessage({
|
|
147
156
|
subject: workers_1.WorkerMessageSubject.WorkerMessageExit,
|
|
@@ -154,7 +163,7 @@ class Spawn {
|
|
|
154
163
|
})(), this.lambdaTimeout);
|
|
155
164
|
// If hard timeout is reached, that means the worker did not exit in time. Terminate the worker.
|
|
156
165
|
this.hardTimeoutTimer = setTimeout(() => void (async () => {
|
|
157
|
-
|
|
166
|
+
console.error('HARD TIMEOUT: Worker did not exit in time. Terminating the worker.');
|
|
158
167
|
if (worker) {
|
|
159
168
|
await worker.terminate();
|
|
160
169
|
}
|
|
@@ -166,7 +175,7 @@ class Spawn {
|
|
|
166
175
|
// If worker exits with process.exit(code), clear the timeouts and exit from
|
|
167
176
|
// main thread.
|
|
168
177
|
worker.on(workers_1.WorkerEvent.WorkerExit, (code) => void (async () => {
|
|
169
|
-
|
|
178
|
+
console.info('Worker exited with exit code: ' + code + '.');
|
|
170
179
|
this.clearTimeouts();
|
|
171
180
|
await this.exitFromMainThread();
|
|
172
181
|
})());
|
|
@@ -177,11 +186,11 @@ class Spawn {
|
|
|
177
186
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageLog) {
|
|
178
187
|
const args = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.args;
|
|
179
188
|
const level = (_b = message.payload) === null || _b === void 0 ? void 0 : _b.level;
|
|
180
|
-
|
|
189
|
+
console.logFn(args, level);
|
|
181
190
|
}
|
|
182
191
|
// If worker sends a message that it has emitted an event, then set alreadyEmitted to true.
|
|
183
192
|
if ((message === null || message === void 0 ? void 0 : message.subject) === workers_1.WorkerMessageSubject.WorkerMessageEmitted) {
|
|
184
|
-
|
|
193
|
+
console.info('Worker has emitted message to ADaaS.');
|
|
185
194
|
this.alreadyEmitted = true;
|
|
186
195
|
}
|
|
187
196
|
});
|
|
@@ -190,12 +199,12 @@ class Spawn {
|
|
|
190
199
|
try {
|
|
191
200
|
const memoryInfo = (0, helpers_2.getMemoryUsage)();
|
|
192
201
|
if (memoryInfo) {
|
|
193
|
-
|
|
202
|
+
console.info(memoryInfo.formattedMessage);
|
|
194
203
|
}
|
|
195
204
|
}
|
|
196
205
|
catch (error) {
|
|
197
206
|
// If memory monitoring fails, log the warning and clear the interval to prevent further issues
|
|
198
|
-
|
|
207
|
+
console.warn('Memory monitoring failed, stopping logging of memory usage interval', error);
|
|
199
208
|
if (this.memoryMonitoringInterval) {
|
|
200
209
|
clearInterval(this.memoryMonitoringInterval);
|
|
201
210
|
this.memoryMonitoringInterval = undefined;
|
|
@@ -216,6 +225,8 @@ class Spawn {
|
|
|
216
225
|
}
|
|
217
226
|
async exitFromMainThread() {
|
|
218
227
|
this.clearTimeouts();
|
|
228
|
+
// eslint-disable-next-line no-global-assign
|
|
229
|
+
console = this.originalConsole;
|
|
219
230
|
if (this.alreadyEmitted) {
|
|
220
231
|
this.resolve();
|
|
221
232
|
return;
|
package/dist/workers/worker.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { workerData } = require('worker_threads');
|
|
3
3
|
require('ts-node').register();
|
|
4
|
+
// Override console with Logger instance
|
|
5
|
+
const { Logger } = require('../logger/logger');
|
|
6
|
+
// eslint-disable-next-line no-global-assign
|
|
7
|
+
console = new Logger({ event: workerData.event, options: workerData.options });
|
|
8
|
+
// Now load the actual worker with console already overridden
|
|
4
9
|
require(workerData.workerPath);
|
package/package.json
CHANGED