@zintrust/workers 0.5.8 → 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/WorkerShutdownDurableObject.d.ts +12 -0
- package/dist/WorkerShutdownDurableObject.js +41 -0
- package/dist/build-manifest.json +40 -12
- package/dist/ui/workers/index.html +202 -0
- package/dist/ui/workers/main.js +1952 -0
- package/dist/ui/workers/styles.css +1350 -0
- package/dist/ui/workers/zintrust.svg +30 -0
- package/package.json +2 -2
- package/src/WorkerFactory.ts +26 -14
- package/src/WorkerInit.ts +20 -6
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<svg width="120" height="120" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="zt-g2d" x1="10" y1="50" x2="90" y2="50" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop stop-color="#22c55e" />
|
|
5
|
+
<stop offset="1" stop-color="#38bdf8" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<circle cx="50" cy="50" r="34" stroke="rgba(255,255,255,0.16)" stroke-width="4" />
|
|
9
|
+
<ellipse cx="50" cy="50" rx="40" ry="18" stroke="url(#zt-g2d)" stroke-width="4" />
|
|
10
|
+
<ellipse cx="50" cy="50" rx="18" ry="40" stroke="url(#zt-g2d)" stroke-width="4" opacity="0.75" />
|
|
11
|
+
<circle cx="50" cy="50" r="6" fill="url(#zt-g2d)" />
|
|
12
|
+
<path
|
|
13
|
+
d="M40 52C35 52 32 49 32 44C32 39 35 36 40 36H48"
|
|
14
|
+
stroke="white"
|
|
15
|
+
stroke-width="6"
|
|
16
|
+
stroke-linecap="round"
|
|
17
|
+
/>
|
|
18
|
+
<path
|
|
19
|
+
d="M60 48C65 48 68 51 68 56C68 61 65 64 60 64H52"
|
|
20
|
+
stroke="white"
|
|
21
|
+
stroke-width="6"
|
|
22
|
+
stroke-linecap="round"
|
|
23
|
+
/>
|
|
24
|
+
<path
|
|
25
|
+
d="M44 50H56"
|
|
26
|
+
stroke="rgba(255,255,255,0.22)"
|
|
27
|
+
stroke-width="6"
|
|
28
|
+
stroke-linecap="round"
|
|
29
|
+
/>
|
|
30
|
+
</svg>
|
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
|
},
|
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
|
}
|