@zintrust/workers 0.5.7 → 0.7.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/dist/WorkerFactory.js +17 -8
- package/dist/WorkerInit.js +7 -2
- package/dist/build-manifest.json +22 -14
- package/package.json +3 -3
- package/src/WorkerFactory.ts +26 -14
- package/src/WorkerInit.ts +20 -6
package/dist/WorkerFactory.js
CHANGED
|
@@ -643,18 +643,22 @@ const resolveStartFromPersistedProcessor = async (name, record, discovered) => {
|
|
|
643
643
|
}
|
|
644
644
|
}
|
|
645
645
|
if (!processor) {
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
646
|
+
const details = {
|
|
647
|
+
kind: 'worker_processor_unresolvable',
|
|
648
|
+
workerName: name,
|
|
649
|
+
processorSpec: spec ?? null,
|
|
650
|
+
isPersistedWorkerProcessorMissing: spec !== undefined && !discovered && !isUrlSpec(spec),
|
|
651
|
+
};
|
|
652
|
+
const unresolvedError = ErrorFactory.createConfigError(`Worker "${name}" processor is not registered or resolvable. Register the processor at startup or persist a processorSpec.`, details);
|
|
650
653
|
throw unresolvedError;
|
|
651
654
|
}
|
|
652
655
|
return processor;
|
|
653
656
|
};
|
|
654
657
|
const isUnresolvablePersistedProcessorError = (value) => {
|
|
655
658
|
return (isObject(value) &&
|
|
656
|
-
value['
|
|
657
|
-
value['
|
|
659
|
+
isObject(value['details']) &&
|
|
660
|
+
value['details']['kind'] === 'worker_processor_unresolvable' &&
|
|
661
|
+
value['details']['isPersistedWorkerProcessorMissing'] === true);
|
|
658
662
|
};
|
|
659
663
|
const discoverFileBackedWorkers = async () => {
|
|
660
664
|
const files = listWorkerDefinitionFiles();
|
|
@@ -2490,11 +2494,16 @@ export const WorkerFactory = Object.freeze({
|
|
|
2490
2494
|
}
|
|
2491
2495
|
catch (error) {
|
|
2492
2496
|
if (isUnresolvablePersistedProcessorError(error)) {
|
|
2497
|
+
const staleDetails = error.details;
|
|
2493
2498
|
Logger.warn(`Purging stale persisted worker "${name}" because its processorSpec is no longer resolvable`, {
|
|
2494
|
-
processorSpec: record.processorSpec ?? null,
|
|
2499
|
+
processorSpec: staleDetails?.processorSpec ?? record.processorSpec ?? null,
|
|
2495
2500
|
});
|
|
2496
2501
|
await WorkerFactory.remove(name, persistenceOverride);
|
|
2497
|
-
throw ErrorFactory.createNotFoundError(`Worker "${name}" was removed because its processorSpec no longer resolves to a live worker module
|
|
2502
|
+
throw ErrorFactory.createNotFoundError(`Worker "${name}" was removed because its processorSpec no longer resolves to a live worker module.`, {
|
|
2503
|
+
kind: 'stale_persisted_worker_purged',
|
|
2504
|
+
workerName: name,
|
|
2505
|
+
processorSpec: staleDetails?.processorSpec ?? record.processorSpec ?? null,
|
|
2506
|
+
});
|
|
2498
2507
|
}
|
|
2499
2508
|
throw error;
|
|
2500
2509
|
}
|
package/dist/WorkerInit.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Sets up auto-scaling and health checks
|
|
8
8
|
* - Ensures graceful startup and shutdown
|
|
9
9
|
*/
|
|
10
|
-
import { Env, Logger } from '@zintrust/core';
|
|
10
|
+
import { Env, isObject, Logger } from '@zintrust/core';
|
|
11
11
|
import { ResourceMonitor } from './ResourceMonitor.js';
|
|
12
12
|
import { WorkerFactory } from './WorkerFactory.js';
|
|
13
13
|
import { WorkerShutdown } from './WorkerShutdown.js';
|
|
@@ -23,6 +23,11 @@ const state = {
|
|
|
23
23
|
autoScaling: false,
|
|
24
24
|
shutdownHandlersRegistered: false,
|
|
25
25
|
};
|
|
26
|
+
const isStalePersistedWorkerPurgedError = (value) => {
|
|
27
|
+
return (isObject(value) &&
|
|
28
|
+
isObject(value['details']) &&
|
|
29
|
+
value['details']['kind'] === 'stale_persisted_worker_purged');
|
|
30
|
+
};
|
|
26
31
|
// ============================================================================
|
|
27
32
|
// Implementation
|
|
28
33
|
// ============================================================================
|
|
@@ -223,7 +228,7 @@ const autoStartOneWorker = async (record) => {
|
|
|
223
228
|
}
|
|
224
229
|
catch (error) {
|
|
225
230
|
const message = error instanceof Error ? error.message : String(error);
|
|
226
|
-
if (
|
|
231
|
+
if (isStalePersistedWorkerPurgedError(error)) {
|
|
227
232
|
Logger.info(`Auto-start purged stale worker ${record.name}: ${message}`);
|
|
228
233
|
return { name: record.name, started: false, skipped: true };
|
|
229
234
|
}
|
package/dist/build-manifest.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/workers",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"buildDate": "2026-04-
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"buildDate": "2026-04-17T14:20:15.922Z",
|
|
5
5
|
"buildEnvironment": {
|
|
6
6
|
"node": "v22.22.1",
|
|
7
7
|
"platform": "darwin",
|
|
8
8
|
"arch": "arm64"
|
|
9
9
|
},
|
|
10
10
|
"git": {
|
|
11
|
-
"commit": "
|
|
11
|
+
"commit": "5b1c8641",
|
|
12
12
|
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
@@ -178,16 +178,16 @@
|
|
|
178
178
|
"sha256": "3869f960c87260588e40941ff91bffcfa0757be7a04815fd28b57dd4840c51df"
|
|
179
179
|
},
|
|
180
180
|
"WorkerFactory.js": {
|
|
181
|
-
"size":
|
|
182
|
-
"sha256": "
|
|
181
|
+
"size": 107617,
|
|
182
|
+
"sha256": "c15002aa229ddf992d2b302a8503f00ecddb78ec97d1afa38de6d9685b9c8b2b"
|
|
183
183
|
},
|
|
184
184
|
"WorkerInit.d.ts": {
|
|
185
185
|
"size": 3284,
|
|
186
186
|
"sha256": "f902550cda7fca36f2db6297d39a4339ed6b5ff1c738da867233309cf0ca8fe1"
|
|
187
187
|
},
|
|
188
188
|
"WorkerInit.js": {
|
|
189
|
-
"size":
|
|
190
|
-
"sha256": "
|
|
189
|
+
"size": 14490,
|
|
190
|
+
"sha256": "d0a59a24bdde2e69d86c33d51dde9661f333c1a68c73509d34e361b32180b423"
|
|
191
191
|
},
|
|
192
192
|
"WorkerMetrics.d.ts": {
|
|
193
193
|
"size": 3304,
|
|
@@ -230,8 +230,8 @@
|
|
|
230
230
|
"sha256": "8af20d462270e7044c6ea983821f5b6e6ce8a5caf39b6e8fefff07c9a0bf071e"
|
|
231
231
|
},
|
|
232
232
|
"build-manifest.json": {
|
|
233
|
-
"size":
|
|
234
|
-
"sha256": "
|
|
233
|
+
"size": 20157,
|
|
234
|
+
"sha256": "60d6a2f80c89eb93765b79190540fb1451602b6e36661cc3c30e037fe6a21977"
|
|
235
235
|
},
|
|
236
236
|
"config/workerConfig.d.ts": {
|
|
237
237
|
"size": 282,
|
|
@@ -415,7 +415,7 @@
|
|
|
415
415
|
},
|
|
416
416
|
"index.js": {
|
|
417
417
|
"size": 2336,
|
|
418
|
-
"sha256": "
|
|
418
|
+
"sha256": "48e1812849b28ad8b2b386afa58113c474be9223852756d6a4eb0e31e4c22a69"
|
|
419
419
|
},
|
|
420
420
|
"queueMonitorHistory.d.ts": {
|
|
421
421
|
"size": 433,
|
|
@@ -510,8 +510,8 @@
|
|
|
510
510
|
"sha256": "5140191207b5620500ac5e1edacefed65956a1ad88739695d545ea7d2b405243"
|
|
511
511
|
},
|
|
512
512
|
"telemetry/routes/dashboard.js": {
|
|
513
|
-
"size":
|
|
514
|
-
"sha256": "
|
|
513
|
+
"size": 23454,
|
|
514
|
+
"sha256": "593773a22c433406d96fafcbb1b93ec7b77cfbea5c6791ae25f718a00e6672f1"
|
|
515
515
|
},
|
|
516
516
|
"type.d.ts": {
|
|
517
517
|
"size": 1649,
|
|
@@ -521,6 +521,14 @@
|
|
|
521
521
|
"size": 11,
|
|
522
522
|
"sha256": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"
|
|
523
523
|
},
|
|
524
|
+
"ui/BrandFavicon.d.ts": {
|
|
525
|
+
"size": 106,
|
|
526
|
+
"sha256": "4f10877579f9366819511e3af3d33728705a1476c5d56db9d5850e50b6cf9130"
|
|
527
|
+
},
|
|
528
|
+
"ui/BrandFavicon.js": {
|
|
529
|
+
"size": 1621,
|
|
530
|
+
"sha256": "d8bf6174015be96e62f76d66aec3e72d70ef88519841a6b422de6378d9f59086"
|
|
531
|
+
},
|
|
524
532
|
"ui/router/EmbeddedAssets.d.ts": {
|
|
525
533
|
"size": 124491,
|
|
526
534
|
"sha256": "3e36de3a75d45f5453934645b49b030592f6d25b61a4467b56cf9ed9a3ce3f88"
|
|
@@ -534,8 +542,8 @@
|
|
|
534
542
|
"sha256": "2e7e0cf6daa881873ead99bdc670f1784760cfc64fa5cdaebb463bd9444e40ae"
|
|
535
543
|
},
|
|
536
544
|
"ui/router/ui.js": {
|
|
537
|
-
"size":
|
|
538
|
-
"sha256": "
|
|
545
|
+
"size": 8056,
|
|
546
|
+
"sha256": "8586d9e4264e449d33eeb88710f708dafdeb77c9b000950263bc3ad6f923efe4"
|
|
539
547
|
},
|
|
540
548
|
"ui/types/worker-ui.d.ts": {
|
|
541
549
|
"size": 5562,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/workers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Worker orchestration and background job management for ZinTrust.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"node": ">=20.0.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@zintrust/core": ">=0.
|
|
43
|
+
"@zintrust/core": ">=0.7.0 <0.8.0",
|
|
44
44
|
"@zintrust/queue-monitor": "*",
|
|
45
45
|
"@zintrust/queue-redis": "*"
|
|
46
46
|
},
|
|
@@ -73,4 +73,4 @@
|
|
|
73
73
|
"prom-client": "^15.1.3",
|
|
74
74
|
"simple-statistics": "^7.8.9"
|
|
75
75
|
}
|
|
76
|
-
}
|
|
76
|
+
}
|
package/src/WorkerFactory.ts
CHANGED
|
@@ -972,16 +972,18 @@ const resolveStartFromPersistedProcessor = async (
|
|
|
972
972
|
}
|
|
973
973
|
|
|
974
974
|
if (!processor) {
|
|
975
|
+
const details = {
|
|
976
|
+
kind: 'worker_processor_unresolvable',
|
|
977
|
+
workerName: name,
|
|
978
|
+
processorSpec: spec ?? null,
|
|
979
|
+
isPersistedWorkerProcessorMissing: spec !== undefined && !discovered && !isUrlSpec(spec),
|
|
980
|
+
} as const;
|
|
981
|
+
|
|
975
982
|
const unresolvedError = ErrorFactory.createConfigError(
|
|
976
|
-
`Worker "${name}" processor is not registered or resolvable. Register the processor at startup or persist a processorSpec
|
|
983
|
+
`Worker "${name}" processor is not registered or resolvable. Register the processor at startup or persist a processorSpec.`,
|
|
984
|
+
details
|
|
977
985
|
);
|
|
978
986
|
|
|
979
|
-
(unresolvedError as Error & { code?: string }).code = 'WORKER_PROCESSOR_UNRESOLVABLE';
|
|
980
|
-
(unresolvedError as Error & { processorSpec?: string | null }).processorSpec = spec ?? null;
|
|
981
|
-
(
|
|
982
|
-
unresolvedError as Error & { isPersistedWorkerProcessorMissing?: boolean }
|
|
983
|
-
).isPersistedWorkerProcessorMissing = spec !== undefined && !discovered && !isUrlSpec(spec);
|
|
984
|
-
|
|
985
987
|
throw unresolvedError;
|
|
986
988
|
}
|
|
987
989
|
|
|
@@ -989,9 +991,12 @@ const resolveStartFromPersistedProcessor = async (
|
|
|
989
991
|
};
|
|
990
992
|
|
|
991
993
|
type UnresolvablePersistedProcessorError = Error & {
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
994
|
+
details?: {
|
|
995
|
+
kind?: string;
|
|
996
|
+
workerName?: string;
|
|
997
|
+
processorSpec?: string | null;
|
|
998
|
+
isPersistedWorkerProcessorMissing?: boolean;
|
|
999
|
+
};
|
|
995
1000
|
};
|
|
996
1001
|
|
|
997
1002
|
const isUnresolvablePersistedProcessorError = (
|
|
@@ -999,8 +1004,9 @@ const isUnresolvablePersistedProcessorError = (
|
|
|
999
1004
|
): value is UnresolvablePersistedProcessorError => {
|
|
1000
1005
|
return (
|
|
1001
1006
|
isObject(value) &&
|
|
1002
|
-
value['
|
|
1003
|
-
value['
|
|
1007
|
+
isObject(value['details']) &&
|
|
1008
|
+
value['details']['kind'] === 'worker_processor_unresolvable' &&
|
|
1009
|
+
value['details']['isPersistedWorkerProcessorMissing'] === true
|
|
1004
1010
|
);
|
|
1005
1011
|
};
|
|
1006
1012
|
|
|
@@ -3415,15 +3421,21 @@ export const WorkerFactory = Object.freeze({
|
|
|
3415
3421
|
processor = await resolveStartFromPersistedProcessor(name, record, discovered);
|
|
3416
3422
|
} catch (error) {
|
|
3417
3423
|
if (isUnresolvablePersistedProcessorError(error)) {
|
|
3424
|
+
const staleDetails = error.details;
|
|
3418
3425
|
Logger.warn(
|
|
3419
3426
|
`Purging stale persisted worker "${name}" because its processorSpec is no longer resolvable`,
|
|
3420
3427
|
{
|
|
3421
|
-
processorSpec: record.processorSpec ?? null,
|
|
3428
|
+
processorSpec: staleDetails?.processorSpec ?? record.processorSpec ?? null,
|
|
3422
3429
|
}
|
|
3423
3430
|
);
|
|
3424
3431
|
await WorkerFactory.remove(name, persistenceOverride);
|
|
3425
3432
|
throw ErrorFactory.createNotFoundError(
|
|
3426
|
-
`Worker "${name}" was removed because its processorSpec no longer resolves to a live worker module
|
|
3433
|
+
`Worker "${name}" was removed because its processorSpec no longer resolves to a live worker module.`,
|
|
3434
|
+
{
|
|
3435
|
+
kind: 'stale_persisted_worker_purged',
|
|
3436
|
+
workerName: name,
|
|
3437
|
+
processorSpec: staleDetails?.processorSpec ?? record.processorSpec ?? null,
|
|
3438
|
+
}
|
|
3427
3439
|
);
|
|
3428
3440
|
}
|
|
3429
3441
|
throw error;
|
package/src/WorkerInit.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Ensures graceful startup and shutdown
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { Env, Logger } from '@zintrust/core';
|
|
11
|
+
import { Env, isObject, Logger } from '@zintrust/core';
|
|
12
12
|
import { ResourceMonitor } from './ResourceMonitor';
|
|
13
13
|
import type { WorkerPersistenceConfig } from './WorkerFactory';
|
|
14
14
|
import { WorkerFactory } from './WorkerFactory';
|
|
@@ -73,6 +73,24 @@ const state: IInitState = {
|
|
|
73
73
|
shutdownHandlersRegistered: false,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
type StalePersistedWorkerPurgedError = Error & {
|
|
77
|
+
details?: {
|
|
78
|
+
kind?: string;
|
|
79
|
+
workerName?: string;
|
|
80
|
+
processorSpec?: string | null;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const isStalePersistedWorkerPurgedError = (
|
|
85
|
+
value: unknown
|
|
86
|
+
): value is StalePersistedWorkerPurgedError => {
|
|
87
|
+
return (
|
|
88
|
+
isObject(value) &&
|
|
89
|
+
isObject(value['details']) &&
|
|
90
|
+
value['details']['kind'] === 'stale_persisted_worker_purged'
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
76
94
|
// ============================================================================
|
|
77
95
|
// Implementation
|
|
78
96
|
// ============================================================================
|
|
@@ -347,11 +365,7 @@ const autoStartOneWorker = async (
|
|
|
347
365
|
} catch (error) {
|
|
348
366
|
const message = error instanceof Error ? error.message : String(error);
|
|
349
367
|
|
|
350
|
-
if (
|
|
351
|
-
message.includes(
|
|
352
|
-
'was removed because its processorSpec no longer resolves to a live worker module.'
|
|
353
|
-
)
|
|
354
|
-
) {
|
|
368
|
+
if (isStalePersistedWorkerPurgedError(error)) {
|
|
355
369
|
Logger.info(`Auto-start purged stale worker ${record.name}: ${message}`);
|
|
356
370
|
return { name: record.name, started: false, skipped: true };
|
|
357
371
|
}
|