@devrev/ts-adaas 1.15.2 → 1.15.3-beta.1
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/common/install-initial-domain-mapping.test.js +2 -1
- package/dist/http/axios-client-internal.test.js +6 -6
- package/dist/multithreading/process-task.d.ts.map +1 -1
- package/dist/multithreading/process-task.js +57 -17
- package/dist/multithreading/worker-adapter/worker-adapter.d.ts.map +1 -1
- package/dist/multithreading/worker-adapter/worker-adapter.js +1 -3
- package/package.json +6 -3
|
@@ -40,7 +40,8 @@ describe(install_initial_domain_mapping_1.installInitialDomainMapping.name, () =
|
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
|
-
|
|
43
|
+
// Use the endpoint from the event to support dynamic ports in parallel tests
|
|
44
|
+
const mockEndpoint = mockEvent.execution_metadata.devrev_endpoint;
|
|
44
45
|
const mockToken = 'test_token';
|
|
45
46
|
// After each test, clear all mocks to prevent state from leaking.
|
|
46
47
|
afterEach(() => {
|
|
@@ -47,7 +47,7 @@ describe('Internal Axios Client', () => {
|
|
|
47
47
|
await axios_client_internal_1.axiosClient.get(jest_setup_1.mockServer.baseUrl + '/test-endpoint');
|
|
48
48
|
expect(jest_setup_1.mockServer.getRequestCount('GET', '/test-endpoint')).toBe(3);
|
|
49
49
|
});
|
|
50
|
-
it('should retry once after
|
|
50
|
+
it('should retry once after delay when response is 429 and Retry-After header is valid value', async () => {
|
|
51
51
|
jest_setup_1.mockServer.setRoute({
|
|
52
52
|
path: '/test-endpoint',
|
|
53
53
|
method: 'GET',
|
|
@@ -56,14 +56,14 @@ describe('Internal Axios Client', () => {
|
|
|
56
56
|
failureCount: 1,
|
|
57
57
|
errorStatus: 429,
|
|
58
58
|
headers: {
|
|
59
|
-
'Retry-After': '
|
|
59
|
+
'Retry-After': '1',
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
});
|
|
63
63
|
await axios_client_internal_1.axiosClient.get(jest_setup_1.mockServer.baseUrl + '/test-endpoint');
|
|
64
64
|
expect(jest_setup_1.mockServer.getRequestCount('GET', '/test-endpoint')).toBe(2);
|
|
65
65
|
});
|
|
66
|
-
it('should retry once after
|
|
66
|
+
it('should retry once after delay and measure time between retries when response is 429 and Retry-After header is valid value', async () => {
|
|
67
67
|
jest_setup_1.mockServer.setRoute({
|
|
68
68
|
path: '/test-endpoint',
|
|
69
69
|
method: 'GET',
|
|
@@ -71,14 +71,14 @@ describe('Internal Axios Client', () => {
|
|
|
71
71
|
retry: {
|
|
72
72
|
failureCount: 1,
|
|
73
73
|
errorStatus: 429,
|
|
74
|
-
headers: { 'Retry-After': '
|
|
74
|
+
headers: { 'Retry-After': '1' },
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
77
|
const startTime = Date.now();
|
|
78
78
|
await axios_client_internal_1.axiosClient.get(jest_setup_1.mockServer.baseUrl + '/test-endpoint');
|
|
79
79
|
const endTime = Date.now();
|
|
80
80
|
const duration = endTime - startTime;
|
|
81
|
-
const expectedDuration =
|
|
81
|
+
const expectedDuration = 1 * 1000;
|
|
82
82
|
expect(duration).toBeGreaterThanOrEqual(expectedDuration);
|
|
83
83
|
expect(duration).toBeLessThan(expectedDuration + 1000);
|
|
84
84
|
});
|
|
@@ -90,7 +90,7 @@ describe('Internal Axios Client', () => {
|
|
|
90
90
|
retry: {
|
|
91
91
|
failureCount: 1,
|
|
92
92
|
errorStatus: 429,
|
|
93
|
-
headers: { 'retry-after': '
|
|
93
|
+
headers: { 'retry-after': '1' },
|
|
94
94
|
},
|
|
95
95
|
});
|
|
96
96
|
await axios_client_internal_1.axiosClient.get(jest_setup_1.mockServer.baseUrl + '/test-endpoint');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-task.d.ts","sourceRoot":"","sources":["../../src/multithreading/process-task.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"process-task.d.ts","sourceRoot":"","sources":["../../src/multithreading/process-task.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;AAsB1B,wBAAgB,WAAW,CAAC,cAAc,EAAE,EAC1C,IAAI,EACJ,SAAS,GACV,EAAE,oBAAoB,CAAC,cAAc,CAAC,QAsFtC"}
|
|
@@ -8,6 +8,19 @@ const logger_context_1 = require("../logger/logger.context");
|
|
|
8
8
|
const state_1 = require("../state/state");
|
|
9
9
|
const workers_1 = require("../types/workers");
|
|
10
10
|
const worker_adapter_1 = require("./worker-adapter/worker-adapter");
|
|
11
|
+
async function handleTimeoutMessage(adapter, taskPromise, onTimeout) {
|
|
12
|
+
console.log('Timeout received. Setting flag and waiting for task to finish.');
|
|
13
|
+
adapter.handleTimeout();
|
|
14
|
+
try {
|
|
15
|
+
await taskPromise;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.warn('Task error during timeout:', (0, logger_1.serializeError)(error));
|
|
19
|
+
}
|
|
20
|
+
console.log('Task finished. Running onTimeout.');
|
|
21
|
+
await (0, logger_context_1.runWithUserLogContext)(async () => onTimeout({ adapter }));
|
|
22
|
+
console.log('Finished executing onTimeout function. Exiting worker.');
|
|
23
|
+
}
|
|
11
24
|
function processTask({ task, onTimeout, }) {
|
|
12
25
|
if (!node_worker_threads_1.isMainThread) {
|
|
13
26
|
void (async () => {
|
|
@@ -27,26 +40,53 @@ function processTask({ task, onTimeout, }) {
|
|
|
27
40
|
initialDomainMapping,
|
|
28
41
|
options,
|
|
29
42
|
});
|
|
30
|
-
if (node_worker_threads_1.parentPort
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
if (!node_worker_threads_1.parentPort || !node_worker_threads_1.workerData.event) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const adapter = new worker_adapter_1.WorkerAdapter({
|
|
47
|
+
event,
|
|
48
|
+
adapterState,
|
|
49
|
+
options,
|
|
50
|
+
});
|
|
51
|
+
// Track whether timeout was requested
|
|
52
|
+
let timeoutRequested = false;
|
|
53
|
+
let taskPromise;
|
|
54
|
+
// Set up message handler BEFORE starting task
|
|
55
|
+
node_worker_threads_1.parentPort.on(workers_1.WorkerEvent.WorkerMessage, (message) => {
|
|
56
|
+
if (message.subject !== workers_1.WorkerMessageSubject.WorkerMessageExit) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
timeoutRequested = true;
|
|
60
|
+
void (0, logger_context_1.runWithSdkLogContext)(async () => {
|
|
61
|
+
try {
|
|
62
|
+
await handleTimeoutMessage(adapter, taskPromise, onTimeout);
|
|
63
|
+
process.exit(0);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error('Error in onTimeout:', (0, logger_1.serializeError)(err));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
35
69
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
});
|
|
71
|
+
// Start task and store the promise
|
|
72
|
+
taskPromise = (0, logger_context_1.runWithUserLogContext)(async () => task({ adapter }));
|
|
73
|
+
try {
|
|
74
|
+
await taskPromise;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
// If timeout was requested, let the timeout handler finish
|
|
78
|
+
if (timeoutRequested) {
|
|
79
|
+
console.log('Task threw during timeout. Letting timeout handler finish.');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
// Task completed normally
|
|
85
|
+
if (!timeoutRequested) {
|
|
86
|
+
console.log('Finished executing task. Exiting worker.');
|
|
48
87
|
process.exit(0);
|
|
49
88
|
}
|
|
89
|
+
// If timeout was requested, the message handler will call process.exit
|
|
50
90
|
}
|
|
51
91
|
catch (error) {
|
|
52
92
|
console.error('Error while processing task.', (0, logger_1.serializeError)(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/worker-adapter/worker-adapter.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,SAAS,EAET,kCAAkC,EAClC,yCAAyC,EACzC,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,EAC7B,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EAEtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EAGrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAkB,MAAM,oCAAoC,CAAC;AAG9E,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,EAClD,KAAK,EACL,YAAY,EACZ,OAAO,GACR,EAAE,sBAAsB,CAAC,cAAc,CAAC,GAAG,aAAa,CAAC,cAAc,CAAC,CAMxE;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,aAAa,CAAC,cAAc;IACvC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC;IACxC,SAAS,EAAE,OAAO,CAAC;IAEnB,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,gBAAgB,CAAU;IAClC,OAAO,CAAC,KAAK,CAAc;IAG3B,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,eAAe,CAAW;IAClC,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAW;gBAEf,EACV,KAAK,EACL,YAAY,EACZ,OAAO,GACR,EAAE,sBAAsB,CAAC,cAAc,CAAC;IAqBzC,IAAI,KAAK,IAAI,YAAY,CAAC,cAAc,CAAC,CAExC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"worker-adapter.d.ts","sourceRoot":"","sources":["../../../src/multithreading/worker-adapter/worker-adapter.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,SAAS,EAET,kCAAkC,EAClC,yCAAyC,EACzC,kBAAkB,EAClB,2BAA2B,EAC3B,2BAA2B,EAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,wBAAwB,EACxB,kBAAkB,EAClB,6BAA6B,EAC7B,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EAEtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EAGrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAkB,MAAM,oCAAoC,CAAC;AAG9E,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,EAClD,KAAK,EACL,YAAY,EACZ,OAAO,GACR,EAAE,sBAAsB,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eAAe,GAChB,EAAE,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAqHnD,gBAAgB,CAAC,EACrB,kBAAkB,GACnB,EAAE;QACD,kBAAkB,EAAE,MAAM,EAAE,CAAC;KAC9B;IA4BK,eAAe,CAAC,EACpB,MAAM,GACP,EAAE;QACD,MAAM,EAAE,6BAA6B,CAAC,wBAAwB,CAAC,CAAC;KACjE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA6E5B,QAAQ,CAAC,EACb,IAAI,EACJ,cAAc,GACf,EAAE;QACD,IAAI,EAAE,kBAAkB,CAAC;QACzB,cAAc,EAAE,cAAc,CAAC;KAChC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkMvB,iBAAiB,CACrB,UAAU,EAAE,oBAAoB,EAChC,MAAM,EAAE,yCAAyC,GAChD,OAAO,CAAC,2BAA2B,CAAC;IAoGvC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAcnB,cAAc,CAAC,EACnB,IAAI,EACJ,MAAM,GACP,EAAE;QACD,IAAI,EAAE,wBAAwB,CAAC;QAC/B,MAAM,EAAE,6BAA6B,CAAC,wBAAwB,CAAC,CAAC;KACjE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAqD7B;;;;;;OAMG;IACG,iBAAiB,CAAC,QAAQ,EAAE,EAChC,MAAM,EACN,UAAU,EACV,SAAa,GACd,EAAE;QACD,MAAM,EAAE,yCAAyC,CAAC;QAClD,UAAU,CAAC,EAAE,kCAAkC,CAC7C,cAAc,EACd,oBAAoB,EAAE,EACtB,QAAQ,CACT,CAAC;QACF,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAyHzC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devrev/ts-adaas",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.3-beta.1",
|
|
4
4
|
"description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
"start": "ts-node src/index.ts",
|
|
12
12
|
"lint": "eslint .",
|
|
13
13
|
"lint:fix": "eslint . --fix",
|
|
14
|
-
"test": "jest --forceExit --
|
|
15
|
-
"test:backwards-compatibility": "jest --forceExit --
|
|
14
|
+
"test": "jest --forceExit --maxWorkers=50% --selectProjects default --",
|
|
15
|
+
"test:backwards-compatibility": "jest --forceExit --selectProjects backwards-compatibility --",
|
|
16
|
+
"test:timeout-handling": "jest --forceExit --selectProjects timeout-handling --",
|
|
17
|
+
"test:slow": "jest --forceExit --selectProjects slow --",
|
|
18
|
+
"test:coverage": "jest --forceExit --coverage --runInBand --"
|
|
16
19
|
},
|
|
17
20
|
"repository": {
|
|
18
21
|
"type": "git",
|