nestworker 2.0.4 → 2.1.0
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/README.md +333 -134
- package/dist/core/worker.interfaces.d.ts +89 -10
- package/dist/core/worker.module.d.ts +21 -11
- package/dist/core/worker.module.js +38 -10
- package/dist/core/worker.module.js.map +1 -1
- package/dist/core/worker.pool.d.ts +26 -6
- package/dist/core/worker.pool.js +246 -101
- package/dist/core/worker.pool.js.map +1 -1
- package/dist/core/worker.service.d.ts +29 -76
- package/dist/core/worker.service.js +108 -80
- package/dist/core/worker.service.js.map +1 -1
- package/dist/decorators/worker-task.decorator.d.ts +7 -25
- package/dist/decorators/worker-task.decorator.js +5 -26
- package/dist/decorators/worker-task.decorator.js.map +1 -1
- package/dist/di/di-serializer.d.ts +9 -8
- package/dist/di/di-serializer.js +69 -46
- package/dist/di/di-serializer.js.map +1 -1
- package/dist/di/worker-container.d.ts +32 -30
- package/dist/di/worker-container.js +130 -70
- package/dist/di/worker-container.js.map +1 -1
- package/dist/discovery/discovery.service.d.ts +2 -9
- package/dist/discovery/discovery.service.js +86 -21
- package/dist/discovery/discovery.service.js.map +1 -1
- package/dist/example/image.service.d.ts +4 -0
- package/dist/example/image.service.js +16 -1
- package/dist/example/image.service.js.map +1 -1
- package/dist/example/main.js +15 -2
- package/dist/example/main.js.map +1 -1
- package/dist/health/worker.health.d.ts +46 -0
- package/dist/health/worker.health.js +77 -0
- package/dist/health/worker.health.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics/worker.metrics.d.ts +65 -0
- package/dist/metrics/worker.metrics.js +122 -0
- package/dist/metrics/worker.metrics.js.map +1 -0
- package/dist/worker/worker-runtime.js +124 -27
- package/dist/worker/worker-runtime.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WorkerContainer – minimal DI container for worker threads.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* Compiled NestJS files import @nestjs/common at the top — requiring them
|
|
6
|
-
* inside a worker triggers the full NestJS bootstrap chain which throws.
|
|
4
|
+
* APPROACH: vm.runInNewContext() with a shared module cache.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Each compiled .js file is executed inside a vm context that has:
|
|
7
|
+
* - A custom require() that blocks NestJS bootstrap imports (returning
|
|
8
|
+
* transparent Proxy stubs so decorator calls at file-eval time are no-ops)
|
|
9
|
+
* - Full access to Node built-ins and third-party packages
|
|
10
|
+
* - Correct __filename / __dirname so relative requires resolve properly
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* → Promise.resolve().then(() => __importStar(require('node:os')))
|
|
18
|
-
*
|
|
19
|
-
* These helpers are defined as `(this && this.__importStar)` at the top of
|
|
20
|
-
* each compiled file — `this` being the module. Inside new Function(),
|
|
21
|
-
* `this` is the global object so all helpers resolve to undefined, causing:
|
|
22
|
-
* Fatal: Error: __importStar is not defined
|
|
23
|
-
*
|
|
24
|
-
* We define the helpers here (Node 16+ always has Object.create, no ternary
|
|
25
|
-
* needed) and inject them alongside require as explicit parameters so both
|
|
26
|
-
* `await import()` and `require()` work correctly inside task methods.
|
|
12
|
+
* This avoids every problem of the new Function() approach:
|
|
13
|
+
* - No alias injection (crypto_1, node_os_1, …)
|
|
14
|
+
* - No TS helper injection (__importStar, __importDefault, …)
|
|
15
|
+
* - No class-body-only extraction — the full compiled file runs as-is
|
|
16
|
+
* - Dynamic import() and require() both work natively
|
|
27
17
|
*/
|
|
28
18
|
export interface SerializedDep {
|
|
29
19
|
name: string;
|
|
30
|
-
|
|
20
|
+
/** Absolute path to the compiled .js file that exports this class */
|
|
21
|
+
filePath: string;
|
|
31
22
|
snapshot: Record<string, unknown>;
|
|
32
23
|
propertyKey: string;
|
|
33
24
|
}
|
|
@@ -38,21 +29,32 @@ export interface SerializedMethod {
|
|
|
38
29
|
}
|
|
39
30
|
export interface SerializedService {
|
|
40
31
|
name: string;
|
|
41
|
-
|
|
32
|
+
/** Absolute path to the compiled .js file that exports this class */
|
|
33
|
+
filePath: string;
|
|
42
34
|
methods: SerializedMethod[];
|
|
43
35
|
deps: SerializedDep[];
|
|
44
36
|
}
|
|
45
37
|
export declare class WorkerContainer {
|
|
46
38
|
private readonly instances;
|
|
39
|
+
/**
|
|
40
|
+
* Module export cache — keyed by absolute file path.
|
|
41
|
+
* Avoids re-executing the same file multiple times when several services
|
|
42
|
+
* live in the same compiled output (monorepo barrel files, etc.).
|
|
43
|
+
*/
|
|
44
|
+
private readonly fileCache;
|
|
47
45
|
load(services: SerializedService[]): void;
|
|
48
46
|
get<T>(name: string): T;
|
|
49
|
-
private
|
|
47
|
+
private reconstructFromFile;
|
|
48
|
+
/**
|
|
49
|
+
* Load a named export from a compiled .js file by running it in a vm
|
|
50
|
+
* context. The context's require() stubs NestJS packages so decorators
|
|
51
|
+
* at file-eval time are silent no-ops, while all other imports resolve
|
|
52
|
+
* normally through the real Node module system.
|
|
53
|
+
*/
|
|
54
|
+
private loadClass;
|
|
50
55
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* require + all four TypeScript CJS helpers are injected as explicit
|
|
54
|
-
* parameters so that compiled dynamic imports (`await import(...)`) and
|
|
55
|
-
* inline require() calls inside task methods work correctly.
|
|
56
|
+
* Execute a compiled .js file in an isolated vm context and return its
|
|
57
|
+
* module.exports. Results are cached by file path.
|
|
56
58
|
*/
|
|
57
|
-
private
|
|
59
|
+
private runFile;
|
|
58
60
|
}
|
|
@@ -2,77 +2,92 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* WorkerContainer – minimal DI container for worker threads.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* Compiled NestJS files import @nestjs/common at the top — requiring them
|
|
7
|
-
* inside a worker triggers the full NestJS bootstrap chain which throws.
|
|
5
|
+
* APPROACH: vm.runInNewContext() with a shared module cache.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* Each compiled .js file is executed inside a vm context that has:
|
|
8
|
+
* - A custom require() that blocks NestJS bootstrap imports (returning
|
|
9
|
+
* transparent Proxy stubs so decorator calls at file-eval time are no-ops)
|
|
10
|
+
* - Full access to Node built-ins and third-party packages
|
|
11
|
+
* - Correct __filename / __dirname so relative requires resolve properly
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* This avoids every problem of the new Function() approach:
|
|
14
|
+
* - No alias injection (crypto_1, node_os_1, …)
|
|
15
|
+
* - No TS helper injection (__importStar, __importDefault, …)
|
|
16
|
+
* - No class-body-only extraction — the full compiled file runs as-is
|
|
17
|
+
* - Dynamic import() and require() both work natively
|
|
18
|
+
*/
|
|
19
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.WorkerContainer = void 0;
|
|
24
|
+
const node_vm_1 = __importDefault(require("node:vm"));
|
|
25
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
26
|
+
const node_module_1 = __importDefault(require("node:module"));
|
|
27
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
28
|
+
/**
|
|
29
|
+
* NestJS packages that must never be required inside a worker.
|
|
30
|
+
* Requiring them triggers the full NestJS bootstrap chain which crashes
|
|
31
|
+
* in an isolated vm context. We stub them with a transparent Proxy so
|
|
32
|
+
* decorator calls (@Injectable, @Controller, etc.) at file-eval time
|
|
33
|
+
* become silent no-ops.
|
|
34
|
+
*/
|
|
35
|
+
const NESTJS_STUB_PACKAGES = new Set([
|
|
36
|
+
'@nestjs/common',
|
|
37
|
+
'@nestjs/core',
|
|
38
|
+
'@nestjs/microservices',
|
|
39
|
+
'@nestjs/platform-express',
|
|
40
|
+
'@nestjs/platform-fastify',
|
|
41
|
+
'reflect-metadata',
|
|
42
|
+
]);
|
|
43
|
+
/**
|
|
44
|
+
* A Proxy that silently absorbs NestJS decorator calls at file-eval time.
|
|
16
45
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
46
|
+
* The apply trap passes through its first argument when it is a function —
|
|
47
|
+
* this preserves the class through decorator factory patterns emitted by TS:
|
|
19
48
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* `this` is the global object so all helpers resolve to undefined, causing:
|
|
23
|
-
* Fatal: Error: __importStar is not defined
|
|
49
|
+
* MyClass = Injectable()(MyClass) ?? MyClass
|
|
50
|
+
* └─ NOOP_STUB() ──┘└─ apply(MyClass) → MyClass ─┘
|
|
24
51
|
*
|
|
25
|
-
*
|
|
26
|
-
* needed) and inject them alongside require as explicit parameters so both
|
|
27
|
-
* `await import()` and `require()` work correctly inside task methods.
|
|
52
|
+
* Without this, NOOP_STUB would replace the class, breaking all exports.
|
|
28
53
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
o[k2] = m[k];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function __setModuleDefault(o, v) {
|
|
45
|
-
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
46
|
-
}
|
|
47
|
-
function __importStar(mod) {
|
|
48
|
-
if (mod && mod.__esModule)
|
|
49
|
-
return mod;
|
|
50
|
-
const result = {};
|
|
51
|
-
if (mod != null) {
|
|
52
|
-
for (const k of Object.getOwnPropertyNames(mod)) {
|
|
53
|
-
if (k !== 'default')
|
|
54
|
-
__createBinding(result, mod, k);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
__setModuleDefault(result, mod);
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
function __importDefault(mod) {
|
|
61
|
-
return mod && mod.__esModule ? mod : { default: mod };
|
|
62
|
-
}
|
|
54
|
+
const NOOP_STUB = new Proxy(
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
56
|
+
function () { }, {
|
|
57
|
+
get: (_t, _k) => NOOP_STUB,
|
|
58
|
+
apply: (_t, _this, args) => {
|
|
59
|
+
// If called with a class/function as the first arg (decorator pattern),
|
|
60
|
+
// return it unchanged so the assignment keeps the real class.
|
|
61
|
+
const first = args[0];
|
|
62
|
+
return typeof first === 'function' ? first : NOOP_STUB;
|
|
63
|
+
},
|
|
64
|
+
construct: () => Object.create(null),
|
|
65
|
+
});
|
|
63
66
|
// ── WorkerContainer ───────────────────────────────────────────────────────
|
|
64
67
|
class WorkerContainer {
|
|
65
68
|
instances = new Map();
|
|
69
|
+
/**
|
|
70
|
+
* Module export cache — keyed by absolute file path.
|
|
71
|
+
* Avoids re-executing the same file multiple times when several services
|
|
72
|
+
* live in the same compiled output (monorepo barrel files, etc.).
|
|
73
|
+
*/
|
|
74
|
+
fileCache = new Map();
|
|
66
75
|
load(services) {
|
|
67
76
|
for (const svc of services) {
|
|
68
|
-
|
|
77
|
+
// Reconstruct each dep from its compiled file + snapshot
|
|
78
|
+
const depsByKey = new Map();
|
|
69
79
|
for (const dep of svc.deps) {
|
|
70
|
-
const inst = this.
|
|
80
|
+
const inst = this.reconstructFromFile(dep.filePath, dep.name, dep.snapshot);
|
|
71
81
|
this.instances.set(dep.name, inst);
|
|
72
|
-
|
|
82
|
+
depsByKey.set(dep.propertyKey, inst);
|
|
83
|
+
}
|
|
84
|
+
// Allocate the service without calling its constructor — deps are
|
|
85
|
+
// assigned by property key so constructor slot order never matters.
|
|
86
|
+
const ServiceClass = this.loadClass(svc.filePath, svc.name);
|
|
87
|
+
const serviceInstance = Object.create(ServiceClass.prototype);
|
|
88
|
+
for (const [key, inst] of depsByKey) {
|
|
89
|
+
serviceInstance[key] = inst;
|
|
73
90
|
}
|
|
74
|
-
const ServiceClass = this.evalClass(svc.classSource, svc.name);
|
|
75
|
-
const serviceInstance = new ServiceClass(...depInstances);
|
|
76
91
|
this.instances.set(svc.name, serviceInstance);
|
|
77
92
|
}
|
|
78
93
|
}
|
|
@@ -82,29 +97,74 @@ class WorkerContainer {
|
|
|
82
97
|
throw new Error(`WorkerContainer: "${name}" not found`);
|
|
83
98
|
return inst;
|
|
84
99
|
}
|
|
85
|
-
|
|
86
|
-
const DepClass = this.
|
|
100
|
+
reconstructFromFile(filePath, className, snapshot) {
|
|
101
|
+
const DepClass = this.loadClass(filePath, className);
|
|
87
102
|
const instance = Object.create(DepClass.prototype);
|
|
88
103
|
Object.assign(instance, snapshot);
|
|
89
104
|
return instance;
|
|
90
105
|
}
|
|
91
106
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* inline require() calls inside task methods work correctly.
|
|
107
|
+
* Load a named export from a compiled .js file by running it in a vm
|
|
108
|
+
* context. The context's require() stubs NestJS packages so decorators
|
|
109
|
+
* at file-eval time are silent no-ops, while all other imports resolve
|
|
110
|
+
* normally through the real Node module system.
|
|
97
111
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
102
|
-
const cls = factory(require, __importStar, __importDefault, __createBinding, __setModuleDefault);
|
|
112
|
+
loadClass(filePath, className) {
|
|
113
|
+
const exports = this.runFile(filePath);
|
|
114
|
+
const cls = exports[className];
|
|
103
115
|
if (typeof cls !== 'function') {
|
|
104
|
-
throw new Error(`WorkerContainer:
|
|
116
|
+
throw new Error(`WorkerContainer: "${className}" not found in "${filePath}". ` +
|
|
117
|
+
`Available exports: ${Object.keys(exports).join(', ')}`);
|
|
105
118
|
}
|
|
106
119
|
return cls;
|
|
107
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Execute a compiled .js file in an isolated vm context and return its
|
|
123
|
+
* module.exports. Results are cached by file path.
|
|
124
|
+
*/
|
|
125
|
+
runFile(filePath) {
|
|
126
|
+
const cached = this.fileCache.get(filePath);
|
|
127
|
+
if (cached)
|
|
128
|
+
return cached;
|
|
129
|
+
const source = node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
130
|
+
const mod = { exports: {} };
|
|
131
|
+
const customRequire = node_module_1.default.createRequire(filePath);
|
|
132
|
+
const sandboxRequire = (id) => {
|
|
133
|
+
if (NESTJS_STUB_PACKAGES.has(id))
|
|
134
|
+
return NOOP_STUB;
|
|
135
|
+
return customRequire(id);
|
|
136
|
+
};
|
|
137
|
+
const context = node_vm_1.default.createContext({
|
|
138
|
+
require: sandboxRequire,
|
|
139
|
+
module: mod,
|
|
140
|
+
exports: mod.exports,
|
|
141
|
+
__filename: filePath,
|
|
142
|
+
__dirname: node_path_1.default.dirname(filePath),
|
|
143
|
+
// Standard globals the compiled output may reference
|
|
144
|
+
console,
|
|
145
|
+
process,
|
|
146
|
+
Buffer,
|
|
147
|
+
URL,
|
|
148
|
+
URLSearchParams,
|
|
149
|
+
fetch,
|
|
150
|
+
setTimeout,
|
|
151
|
+
clearTimeout,
|
|
152
|
+
setInterval,
|
|
153
|
+
clearInterval,
|
|
154
|
+
setImmediate,
|
|
155
|
+
clearImmediate,
|
|
156
|
+
Promise,
|
|
157
|
+
// Make the context's global === the context itself so that
|
|
158
|
+
// `(this && this.__importStar)` patterns resolve to the context global
|
|
159
|
+
// rather than to undefined (as they would in new Function()).
|
|
160
|
+
global: undefined, // set below after createContext
|
|
161
|
+
});
|
|
162
|
+
// Wire global → context so self-referential global patterns work
|
|
163
|
+
context.global = context;
|
|
164
|
+
node_vm_1.default.runInContext(source, context, { filename: filePath });
|
|
165
|
+
this.fileCache.set(filePath, mod.exports);
|
|
166
|
+
return mod.exports;
|
|
167
|
+
}
|
|
108
168
|
}
|
|
109
169
|
exports.WorkerContainer = WorkerContainer;
|
|
110
170
|
//# sourceMappingURL=worker-container.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-container.js","sourceRoot":"","sources":["../../src/di/worker-container.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"worker-container.js","sourceRoot":"","sources":["../../src/di/worker-container.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;AAEH,sDAAyB;AACzB,0DAAiC;AACjC,8DAAqC;AACrC,sDAAyB;AAwBzB;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,gBAAgB;IAChB,cAAc;IACd,uBAAuB;IACvB,0BAA0B;IAC1B,0BAA0B;IAC1B,kBAAkB;CACnB,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,MAAM,SAAS,GAAY,IAAI,KAAK;AAClC,gEAAgE;AAChE,cAAa,CAAC,EACd;IACE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,SAAS;IAC1B,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACzB,wEAAwE;QACxE,8DAA8D;QAC9D,MAAM,KAAK,GAAI,IAAkB,CAAC,CAAC,CAAC,CAAC;QACrC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACzD,CAAC;IACD,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;CACrC,CACF,CAAC;AAEF,6EAA6E;AAE7E,MAAa,eAAe;IACT,SAAS,GAAG,IAAI,GAAG,EAAmB,CAAC;IAExD;;;;OAIG;IACc,SAAS,GAAG,IAAI,GAAG,EAAmC,CAAC;IAExE,IAAI,CAAC,QAA6B;QAChC,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;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,aAAa,CAAC;YAC/B,OAAO,EAAE,cAAc;YACvB,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,UAAU,EAAE,QAAQ;YACpB,SAAS,EAAE,mBAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;YACrC,qDAAqD;YACrD,OAAO;YACP,OAAO;YACP,MAAM;YACN,GAAG;YACH,eAAe;YACf,KAAK;YACL,UAAU;YACV,YAAY;YACZ,WAAW;YACX,aAAa;YACb,YAAY;YACZ,cAAc;YACd,OAAO;YACP,2DAA2D;YAC3D,uEAAuE;YACvE,8DAA8D;YAC9D,MAAM,EAAE,SAAoB,EAAE,gCAAgC;SAC/D,CAAC,CAAC;QAEH,iEAAiE;QAChE,OAAmC,CAAC,MAAM,GAAG,OAAO,CAAC;QAEtD,iBAAE,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEzD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,GAAG,CAAC,OAAO,CAAC;IACrB,CAAC;CACF;AA7HD,0CA6HC"}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { ModuleRef, ModulesContainer } from '@nestjs/core';
|
|
2
2
|
import type { DiscoveredTask } from '../core/worker.interfaces';
|
|
3
|
-
/**
|
|
4
|
-
* WorkerDiscoveryService
|
|
5
|
-
*
|
|
6
|
-
* Scans both module.providers AND module.controllers so that
|
|
7
|
-
* @WorkerClass() / @WorkerTask() work on NestJS controllers too.
|
|
8
|
-
*
|
|
9
|
-
* scan() is called lazily by WorkerService on the first run() call,
|
|
10
|
-
* guaranteeing all providers and controllers are fully instantiated.
|
|
11
|
-
*/
|
|
12
3
|
export declare class WorkerDiscoveryService {
|
|
13
4
|
private readonly modulesContainer;
|
|
14
5
|
private readonly moduleRef;
|
|
6
|
+
private readonly logger;
|
|
15
7
|
private scanned;
|
|
16
8
|
private discovered;
|
|
17
9
|
constructor(modulesContainer: ModulesContainer, moduleRef: ModuleRef);
|
|
18
10
|
scan(): DiscoveredTask[];
|
|
19
11
|
private inspectWrapper;
|
|
12
|
+
private resolveToken;
|
|
20
13
|
}
|
|
@@ -8,23 +8,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var WorkerDiscoveryService_1;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
13
|
exports.WorkerDiscoveryService = void 0;
|
|
13
14
|
const common_1 = require("@nestjs/common");
|
|
14
15
|
const core_1 = require("@nestjs/core");
|
|
15
16
|
const worker_task_decorator_1 = require("../decorators/worker-task.decorator");
|
|
16
|
-
|
|
17
|
-
* WorkerDiscoveryService
|
|
18
|
-
*
|
|
19
|
-
* Scans both module.providers AND module.controllers so that
|
|
20
|
-
* @WorkerClass() / @WorkerTask() work on NestJS controllers too.
|
|
21
|
-
*
|
|
22
|
-
* scan() is called lazily by WorkerService on the first run() call,
|
|
23
|
-
* guaranteeing all providers and controllers are fully instantiated.
|
|
24
|
-
*/
|
|
25
|
-
let WorkerDiscoveryService = class WorkerDiscoveryService {
|
|
17
|
+
let WorkerDiscoveryService = WorkerDiscoveryService_1 = class WorkerDiscoveryService {
|
|
26
18
|
modulesContainer;
|
|
27
19
|
moduleRef;
|
|
20
|
+
logger = new common_1.Logger(WorkerDiscoveryService_1.name);
|
|
28
21
|
scanned = false;
|
|
29
22
|
discovered = [];
|
|
30
23
|
constructor(modulesContainer, moduleRef) {
|
|
@@ -36,59 +29,131 @@ let WorkerDiscoveryService = class WorkerDiscoveryService {
|
|
|
36
29
|
return this.discovered;
|
|
37
30
|
this.scanned = true;
|
|
38
31
|
for (const module of this.modulesContainer.values()) {
|
|
39
|
-
// Scan providers (services, repositories, etc.)
|
|
40
32
|
for (const wrapper of module.providers.values()) {
|
|
41
33
|
this.inspectWrapper(wrapper);
|
|
42
34
|
}
|
|
43
|
-
// Scan controllers — NestJS registers these separately
|
|
44
35
|
for (const wrapper of module.controllers.values()) {
|
|
45
36
|
this.inspectWrapper(wrapper);
|
|
46
37
|
}
|
|
47
38
|
}
|
|
39
|
+
if (this.discovered.length === 0) {
|
|
40
|
+
this.logger.warn('No @WorkerTask methods found. Ensure at least one class is decorated ' +
|
|
41
|
+
'with @WorkerClass() and has methods decorated with @WorkerTask().');
|
|
42
|
+
}
|
|
48
43
|
return this.discovered;
|
|
49
44
|
}
|
|
50
45
|
inspectWrapper(wrapper) {
|
|
51
46
|
const { instance, metatype } = wrapper;
|
|
52
47
|
if (!instance || !metatype)
|
|
53
48
|
return;
|
|
54
|
-
|
|
55
|
-
if (!isWorkerClass)
|
|
49
|
+
if (!Reflect.getMetadata(worker_task_decorator_1.WORKER_CLASS_META, metatype))
|
|
56
50
|
return;
|
|
57
51
|
const serviceName = metatype.name;
|
|
58
|
-
const proto =
|
|
52
|
+
const proto = metatype.prototype;
|
|
53
|
+
// ── serialised deps ───────────────────────────────────────────────────
|
|
59
54
|
const depTypes = Reflect.getMetadata(worker_task_decorator_1.WORKER_DEPS_META, metatype) ?? [];
|
|
60
|
-
const deps = depTypes.map((token) =>
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const deps = depTypes.map((token) => this.resolveToken(token, serviceName, 'deps'));
|
|
56
|
+
// ── proxy services ────────────────────────────────────────────────────
|
|
57
|
+
const proxyTypes = Reflect.getMetadata(worker_task_decorator_1.WORKER_PROXY_META, metatype) ?? [];
|
|
58
|
+
const proxyInstances = proxyTypes.map((token) => {
|
|
59
|
+
const svcInstance = this.resolveToken(token, serviceName, 'proxy');
|
|
60
|
+
const tokenName = token.name ?? 'unknown';
|
|
61
|
+
const propertyKey = findPropertyKey(instance, svcInstance) ?? camelCase(tokenName);
|
|
62
|
+
if (!findPropertyKey(instance, svcInstance)) {
|
|
63
|
+
this.logger.warn(`${serviceName}: could not find property key for proxy "${tokenName}" ` +
|
|
64
|
+
`— falling back to camelCase: "${propertyKey}".`);
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const methodNames = [];
|
|
67
|
+
if (svcInstance) {
|
|
68
|
+
let cursor = Object.getPrototypeOf(svcInstance);
|
|
69
|
+
while (cursor && cursor !== Object.prototype) {
|
|
70
|
+
for (const k of Object.getOwnPropertyNames(cursor)) {
|
|
71
|
+
if (k !== 'constructor' && !methodNames.includes(k)) {
|
|
72
|
+
const desc = Object.getOwnPropertyDescriptor(cursor, k);
|
|
73
|
+
if (desc && typeof desc.value === 'function')
|
|
74
|
+
methodNames.push(k);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
cursor = Object.getPrototypeOf(cursor);
|
|
78
|
+
}
|
|
66
79
|
}
|
|
80
|
+
return { propertyKey, methodNames, instance: svcInstance ?? {} };
|
|
67
81
|
});
|
|
82
|
+
// ── @WorkerTask methods ───────────────────────────────────────────────
|
|
83
|
+
let tasksFound = 0;
|
|
68
84
|
for (const methodName of Object.getOwnPropertyNames(proto)) {
|
|
69
85
|
if (methodName === 'constructor')
|
|
70
86
|
continue;
|
|
71
87
|
const options = Reflect.getMetadata(worker_task_decorator_1.WORKER_METHOD_META, proto, methodName);
|
|
72
88
|
if (!options)
|
|
73
89
|
continue;
|
|
90
|
+
tasksFound++;
|
|
91
|
+
// Normalise retryDelay: function form → serialised as max of first 3 calls
|
|
92
|
+
// (functions can't cross the thread boundary; we store the numeric value)
|
|
93
|
+
let retryDelay;
|
|
94
|
+
if (typeof options.retryDelay === 'function') {
|
|
95
|
+
// Store delays for attempts 1-3 as a simple average to give workers
|
|
96
|
+
// a representative delay. For production use, pass a number.
|
|
97
|
+
const fn = options.retryDelay;
|
|
98
|
+
retryDelay = Math.round((fn(1) + fn(2) + fn(3)) / 3);
|
|
99
|
+
this.logger.warn(`${serviceName}.${methodName}: retryDelay as a function is not supported ` +
|
|
100
|
+
`across thread boundaries. Computed average: ${retryDelay}ms. ` +
|
|
101
|
+
`Pass a number for precise control.`);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
retryDelay = options.retryDelay;
|
|
105
|
+
}
|
|
74
106
|
const fn = instance[methodName].bind(instance);
|
|
75
107
|
this.discovered.push({
|
|
76
108
|
serviceName,
|
|
77
109
|
methodName,
|
|
78
110
|
priority: options.priority ?? 'NORMAL',
|
|
79
111
|
timeout: options.timeout,
|
|
112
|
+
retry: options.retry,
|
|
113
|
+
retryDelay,
|
|
80
114
|
fn,
|
|
81
115
|
metatype: metatype,
|
|
82
116
|
instance,
|
|
83
117
|
deps,
|
|
118
|
+
proxyInstances,
|
|
84
119
|
});
|
|
120
|
+
this.logger.debug(`Registered task: ${serviceName}.${methodName} ` +
|
|
121
|
+
`[priority=${options.priority ?? 'NORMAL'}` +
|
|
122
|
+
`${options.timeout ? `, timeout=${options.timeout}ms` : ''}` +
|
|
123
|
+
`${options.retry ? `, retry=${options.retry}` : ''}]`);
|
|
124
|
+
}
|
|
125
|
+
if (tasksFound === 0) {
|
|
126
|
+
this.logger.warn(`${serviceName} has @WorkerClass() but no @WorkerTask() methods.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
resolveToken(token, ownerName, role) {
|
|
130
|
+
try {
|
|
131
|
+
return this.moduleRef.get(token, { strict: false });
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
const name = token.name ?? String(token);
|
|
135
|
+
this.logger.error(`${ownerName}: failed to resolve ${role} token "${name}". ` +
|
|
136
|
+
`Original error: ${err.message}`);
|
|
137
|
+
return undefined;
|
|
85
138
|
}
|
|
86
139
|
}
|
|
87
140
|
};
|
|
88
141
|
exports.WorkerDiscoveryService = WorkerDiscoveryService;
|
|
89
|
-
exports.WorkerDiscoveryService = WorkerDiscoveryService = __decorate([
|
|
142
|
+
exports.WorkerDiscoveryService = WorkerDiscoveryService = WorkerDiscoveryService_1 = __decorate([
|
|
90
143
|
(0, common_1.Injectable)(),
|
|
91
144
|
__metadata("design:paramtypes", [core_1.ModulesContainer,
|
|
92
145
|
core_1.ModuleRef])
|
|
93
146
|
], WorkerDiscoveryService);
|
|
147
|
+
function findPropertyKey(serviceInstance, depInstance) {
|
|
148
|
+
if (!serviceInstance || !depInstance || typeof serviceInstance !== 'object')
|
|
149
|
+
return undefined;
|
|
150
|
+
for (const key of Object.getOwnPropertyNames(serviceInstance)) {
|
|
151
|
+
if (serviceInstance[key] === depInstance)
|
|
152
|
+
return key;
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
function camelCase(name) {
|
|
157
|
+
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
158
|
+
}
|
|
94
159
|
//# sourceMappingURL=discovery.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.service.js","sourceRoot":"","sources":["../../src/discovery/discovery.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"discovery.service.js","sourceRoot":"","sources":["../../src/discovery/discovery.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,uCAA2D;AAE3D,+EAM6C;AAItC,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IAMd;IACA;IANF,MAAM,GAAG,IAAI,eAAM,CAAC,wBAAsB,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,GAAG,KAAK,CAAC;IAChB,UAAU,GAAqB,EAAE,CAAC;IAE1C,YACmB,gBAAkC,EAClC,SAAoB;QADpB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,cAAS,GAAT,SAAS,CAAW;IACpC,CAAC;IAEJ,IAAI;QACF,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,UAAU,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;Q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GAAE;qCAO0B,uBAAgB;QACvB,gBAAS;GAP5B,sBAAsB,CAiKlC;AAED,SAAS,eAAe,CACtB,eAAwB,EACxB,WAAoB;IAEpB,IAAI,CAAC,eAAe,IAAI,CAAC,WAAW,IAAI,OAAO,eAAe,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC9F,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,EAAE,CAAC;QAC9D,IAAK,eAA2C,CAAC,GAAG,CAAC,KAAK,WAAW;YAAE,OAAO,GAAG,CAAC;IACpF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -41,11 +41,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
41
41
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
42
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
43
|
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
44
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
48
|
exports.ImageService = void 0;
|
|
46
49
|
const common_1 = require("@nestjs/common");
|
|
47
50
|
const worker_task_decorator_1 = require("../decorators/worker-task.decorator");
|
|
48
51
|
const config_service_1 = require("./config.service");
|
|
52
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
49
53
|
let ImageService = class ImageService {
|
|
50
54
|
configService;
|
|
51
55
|
constructor(configService) {
|
|
@@ -74,10 +78,15 @@ let ImageService = class ImageService {
|
|
|
74
78
|
const os = require('node:os');
|
|
75
79
|
return `Require os size ${os.cpus().length}`;
|
|
76
80
|
}
|
|
81
|
+
async outlineModule() {
|
|
82
|
+
const p = await promises_1.default.readFile('./package.json', 'utf-8');
|
|
83
|
+
const f = (await fetch('https://api.github.com')).status;
|
|
84
|
+
return { p: p.length, f };
|
|
85
|
+
}
|
|
77
86
|
};
|
|
78
87
|
exports.ImageService = ImageService;
|
|
79
88
|
__decorate([
|
|
80
|
-
(0, worker_task_decorator_1.WorkerTask)(),
|
|
89
|
+
(0, worker_task_decorator_1.WorkerTask)({ priority: 'HIGH' }),
|
|
81
90
|
__metadata("design:type", Function),
|
|
82
91
|
__metadata("design:paramtypes", [Number]),
|
|
83
92
|
__metadata("design:returntype", Number)
|
|
@@ -100,6 +109,12 @@ __decorate([
|
|
|
100
109
|
__metadata("design:paramtypes", []),
|
|
101
110
|
__metadata("design:returntype", Promise)
|
|
102
111
|
], ImageService.prototype, "moduleRequire", null);
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, worker_task_decorator_1.WorkerTask)(),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", []),
|
|
116
|
+
__metadata("design:returntype", Promise)
|
|
117
|
+
], ImageService.prototype, "outlineModule", null);
|
|
103
118
|
exports.ImageService = ImageService = __decorate([
|
|
104
119
|
(0, common_1.Injectable)(),
|
|
105
120
|
(0, worker_task_decorator_1.WorkerClass)({ deps: [config_service_1.ConfigService] }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.service.js","sourceRoot":"","sources":["../../src/example/image.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image.service.js","sourceRoot":"","sources":["../../src/example/image.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+EAA8E;AAC9E,qDAAiD;AACjD,2DAA6B;AAItB,IAAM,YAAY,GAAlB,MAAM,YAAY;IACM;IAA7B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb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