@zintrust/workers 0.5.5 → 0.5.7
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 +36 -5
- package/dist/WorkerInit.js +4 -0
- package/dist/WorkerShutdownDurableObject.d.ts +12 -0
- package/dist/WorkerShutdownDurableObject.js +41 -0
- package/dist/build-manifest.json +40 -20
- 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 +57 -7
- package/src/WorkerInit.ts +10 -0
|
@@ -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.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "Worker orchestration and background job management for ZinTrust.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -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,14 +972,38 @@ const resolveStartFromPersistedProcessor = async (
|
|
|
972
972
|
}
|
|
973
973
|
|
|
974
974
|
if (!processor) {
|
|
975
|
-
|
|
975
|
+
const unresolvedError = ErrorFactory.createConfigError(
|
|
976
976
|
`Worker "${name}" processor is not registered or resolvable. Register the processor at startup or persist a processorSpec.`
|
|
977
977
|
);
|
|
978
|
+
|
|
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
|
+
throw unresolvedError;
|
|
978
986
|
}
|
|
979
987
|
|
|
980
988
|
return processor;
|
|
981
989
|
};
|
|
982
990
|
|
|
991
|
+
type UnresolvablePersistedProcessorError = Error & {
|
|
992
|
+
code?: string;
|
|
993
|
+
processorSpec?: string | null;
|
|
994
|
+
isPersistedWorkerProcessorMissing?: boolean;
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
const isUnresolvablePersistedProcessorError = (
|
|
998
|
+
value: unknown
|
|
999
|
+
): value is UnresolvablePersistedProcessorError => {
|
|
1000
|
+
return (
|
|
1001
|
+
isObject(value) &&
|
|
1002
|
+
value['code'] === 'WORKER_PROCESSOR_UNRESOLVABLE' &&
|
|
1003
|
+
value['isPersistedWorkerProcessorMissing'] === true
|
|
1004
|
+
);
|
|
1005
|
+
};
|
|
1006
|
+
|
|
983
1007
|
const discoverFileBackedWorkers = async (): Promise<DiscoveredFileWorker[]> => {
|
|
984
1008
|
const files = listWorkerDefinitionFiles();
|
|
985
1009
|
if (files.length === 0) return [];
|
|
@@ -1080,8 +1104,8 @@ const setCachedProcessor = (key: string, entry: CachedProcessor, maxSize: number
|
|
|
1080
1104
|
};
|
|
1081
1105
|
|
|
1082
1106
|
const isAllowedRemoteHost = (host: string): boolean => {
|
|
1083
|
-
const allowlist =
|
|
1084
|
-
|
|
1107
|
+
const allowlist = getProcessorSpecConfig().remoteAllowlist.map((value: string) =>
|
|
1108
|
+
value.toLowerCase()
|
|
1085
1109
|
);
|
|
1086
1110
|
return allowlist.includes(host.toLowerCase());
|
|
1087
1111
|
};
|
|
@@ -3386,7 +3410,24 @@ export const WorkerFactory = Object.freeze({
|
|
|
3386
3410
|
throw ErrorFactory.createConfigError(`Worker "${name}" is inactive`);
|
|
3387
3411
|
}
|
|
3388
3412
|
|
|
3389
|
-
|
|
3413
|
+
let processor: WorkerFactoryConfig['processor'];
|
|
3414
|
+
try {
|
|
3415
|
+
processor = await resolveStartFromPersistedProcessor(name, record, discovered);
|
|
3416
|
+
} catch (error) {
|
|
3417
|
+
if (isUnresolvablePersistedProcessorError(error)) {
|
|
3418
|
+
Logger.warn(
|
|
3419
|
+
`Purging stale persisted worker "${name}" because its processorSpec is no longer resolvable`,
|
|
3420
|
+
{
|
|
3421
|
+
processorSpec: record.processorSpec ?? null,
|
|
3422
|
+
}
|
|
3423
|
+
);
|
|
3424
|
+
await WorkerFactory.remove(name, persistenceOverride);
|
|
3425
|
+
throw ErrorFactory.createNotFoundError(
|
|
3426
|
+
`Worker "${name}" was removed because its processorSpec no longer resolves to a live worker module.`
|
|
3427
|
+
);
|
|
3428
|
+
}
|
|
3429
|
+
throw error;
|
|
3430
|
+
}
|
|
3390
3431
|
|
|
3391
3432
|
await WorkerFactory.create({
|
|
3392
3433
|
name: record.name,
|
|
@@ -3444,8 +3485,7 @@ export const WorkerFactory = Object.freeze({
|
|
|
3444
3485
|
*/
|
|
3445
3486
|
async remove(name: string, persistenceOverride?: WorkerPersistenceConfig): Promise<void> {
|
|
3446
3487
|
const instance = workers.get(name);
|
|
3447
|
-
|
|
3448
|
-
const store = await validateAndGetStore(name, instance?.config, persistenceOverride);
|
|
3488
|
+
const store = await getStoreForWorker(instance?.config, persistenceOverride);
|
|
3449
3489
|
|
|
3450
3490
|
if (instance) {
|
|
3451
3491
|
await WorkerFactory.stop(name, persistenceOverride);
|
|
@@ -3465,7 +3505,17 @@ export const WorkerFactory = Object.freeze({
|
|
|
3465
3505
|
workers.delete(name);
|
|
3466
3506
|
}
|
|
3467
3507
|
|
|
3468
|
-
|
|
3508
|
+
try {
|
|
3509
|
+
const persisted = await store.get(name);
|
|
3510
|
+
if (persisted) {
|
|
3511
|
+
await store.remove(name);
|
|
3512
|
+
}
|
|
3513
|
+
} finally {
|
|
3514
|
+
if (Cloudflare.getWorkersEnv() !== null && store.close) {
|
|
3515
|
+
await store.close();
|
|
3516
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
|
|
3469
3519
|
Logger.info(`Worker removed: ${name}`);
|
|
3470
3520
|
},
|
|
3471
3521
|
|
package/src/WorkerInit.ts
CHANGED
|
@@ -346,6 +346,16 @@ const autoStartOneWorker = async (
|
|
|
346
346
|
return { name: record.name, started: true, skipped: false };
|
|
347
347
|
} catch (error) {
|
|
348
348
|
const message = error instanceof Error ? error.message : String(error);
|
|
349
|
+
|
|
350
|
+
if (
|
|
351
|
+
message.includes(
|
|
352
|
+
'was removed because its processorSpec no longer resolves to a live worker module.'
|
|
353
|
+
)
|
|
354
|
+
) {
|
|
355
|
+
Logger.info(`Auto-start purged stale worker ${record.name}: ${message}`);
|
|
356
|
+
return { name: record.name, started: false, skipped: true };
|
|
357
|
+
}
|
|
358
|
+
|
|
349
359
|
Logger.warn(`Auto-start failed for worker ${record.name}: ${message}`);
|
|
350
360
|
return { name: record.name, started: false, skipped: false };
|
|
351
361
|
}
|