@zintrust/workers 0.4.89 → 0.4.92
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/DeadLetterQueue.js +3 -3
- package/dist/WorkerFactory.js +5 -5
- package/dist/WorkerInit.js +2 -2
- package/dist/build-manifest.json +18 -46
- package/dist/config/workerConfig.d.ts +2 -0
- package/dist/config/workerConfig.js +51 -4
- package/package.json +1 -1
- package/src/DeadLetterQueue.ts +3 -3
- package/src/WorkerFactory.ts +5 -5
- package/src/WorkerInit.ts +2 -2
- package/src/config/workerConfig.ts +62 -4
- package/dist/WorkerShutdownDurableObject.d.ts +0 -12
- package/dist/WorkerShutdownDurableObject.js +0 -41
- package/dist/ui/workers/index.html +0 -202
- package/dist/ui/workers/main.js +0 -1952
- package/dist/ui/workers/styles.css +0 -1350
- package/dist/ui/workers/zintrust.svg +0 -30
package/dist/DeadLetterQueue.js
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
6
|
import { ErrorFactory, Logger, createRedisConnection } from '@zintrust/core';
|
|
7
|
-
import {
|
|
7
|
+
import { keyPrefixFor } from './config/workerConfig.js';
|
|
8
8
|
// Redis key prefixes - using workers package prefix system
|
|
9
9
|
const getDLQPrefix = () => {
|
|
10
|
-
return
|
|
10
|
+
return keyPrefixFor('dlq');
|
|
11
11
|
};
|
|
12
12
|
const getAuditPrefix = () => {
|
|
13
|
-
return
|
|
13
|
+
return keyPrefixFor('dlq', 'audit');
|
|
14
14
|
};
|
|
15
15
|
// Internal state
|
|
16
16
|
let redisClient = null;
|
package/dist/WorkerFactory.js
CHANGED
|
@@ -22,7 +22,7 @@ import { ResourceMonitor } from './ResourceMonitor.js';
|
|
|
22
22
|
import { WorkerMetrics } from './WorkerMetrics.js';
|
|
23
23
|
import { WorkerRegistry } from './WorkerRegistry.js';
|
|
24
24
|
import { WorkerVersioning } from './WorkerVersioning.js';
|
|
25
|
-
import {
|
|
25
|
+
import { resolveWorkerKeyPrefix } from './config/workerConfig.js';
|
|
26
26
|
import { recordQueueMonitorJob } from './queueMonitorHistory.js';
|
|
27
27
|
import { DbWorkerStore, InMemoryWorkerStore, RedisWorkerStore, } from './storage/WorkerStore.js';
|
|
28
28
|
const path = NodeSingletons.path;
|
|
@@ -1496,7 +1496,7 @@ const normalizeExplicitPersistence = (persistence) => {
|
|
|
1496
1496
|
return {
|
|
1497
1497
|
driver: 'redis',
|
|
1498
1498
|
redis: persistence.redis,
|
|
1499
|
-
keyPrefix: keyPrefix
|
|
1499
|
+
keyPrefix: resolveWorkerKeyPrefix(persistence.keyPrefix),
|
|
1500
1500
|
};
|
|
1501
1501
|
}
|
|
1502
1502
|
const clientIsConnection = typeof persistence.client === 'string';
|
|
@@ -1532,7 +1532,7 @@ const resolvePersistenceConfig = (config) => {
|
|
|
1532
1532
|
env: true,
|
|
1533
1533
|
db: persistenceDbOverride ? 'WORKER_PERSISTENCE_REDIS_DB' : 'REDIS_QUEUE_DB',
|
|
1534
1534
|
},
|
|
1535
|
-
keyPrefix:
|
|
1535
|
+
keyPrefix: resolveWorkerKeyPrefix(),
|
|
1536
1536
|
};
|
|
1537
1537
|
}
|
|
1538
1538
|
if (driver === 'db' || driver === 'database') {
|
|
@@ -1577,7 +1577,7 @@ const resolveWorkerStore = async (config) => {
|
|
|
1577
1577
|
}
|
|
1578
1578
|
else if (persistence.driver === 'redis') {
|
|
1579
1579
|
const redisConfig = resolveRedisConfigWithFallback(persistence.redis, config.infrastructure?.redis, 'Worker persistence requires redis config (persistence.redis or infrastructure.redis)', 'infrastructure.persistence.redis');
|
|
1580
|
-
const key_prefix = persistence.keyPrefix
|
|
1580
|
+
const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
|
|
1581
1581
|
logRedisPersistenceConfig(redisConfig, key_prefix, 'resolveWorkerStore');
|
|
1582
1582
|
const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
|
|
1583
1583
|
next = RedisWorkerStore.create(client, key_prefix);
|
|
@@ -1621,7 +1621,7 @@ const createWorkerStore = async (persistence) => {
|
|
|
1621
1621
|
}
|
|
1622
1622
|
if (persistence.driver === 'redis') {
|
|
1623
1623
|
const redisConfig = resolveRedisConfigWithFallback(persistence.redis ?? { env: true }, undefined, 'Worker persistence requires redis config (persistence.redis or REDIS_* env values)', 'persistence.redis');
|
|
1624
|
-
const key_prefix = persistence.keyPrefix
|
|
1624
|
+
const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
|
|
1625
1625
|
logRedisPersistenceConfig(redisConfig, key_prefix, 'createWorkerStore');
|
|
1626
1626
|
const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
|
|
1627
1627
|
return RedisWorkerStore.create(client, key_prefix);
|
package/dist/WorkerInit.js
CHANGED
|
@@ -11,7 +11,7 @@ import { Env, 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';
|
|
14
|
-
import {
|
|
14
|
+
import { resolveWorkerKeyPrefix } from './config/workerConfig.js';
|
|
15
15
|
// ============================================================================
|
|
16
16
|
// State
|
|
17
17
|
// ============================================================================
|
|
@@ -53,7 +53,7 @@ function initializeResourceMonitoring(enableResourceMonitoring, resourceMonitori
|
|
|
53
53
|
}
|
|
54
54
|
const getPersistenceOverride = (driver) => {
|
|
55
55
|
if (driver === 'redis') {
|
|
56
|
-
return { driver: 'redis', keyPrefix:
|
|
56
|
+
return { driver: 'redis', keyPrefix: resolveWorkerKeyPrefix() };
|
|
57
57
|
}
|
|
58
58
|
if (driver === 'memory') {
|
|
59
59
|
return { driver: 'memory' };
|
package/dist/build-manifest.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/workers",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"buildDate": "2026-04-
|
|
3
|
+
"version": "0.4.92",
|
|
4
|
+
"buildDate": "2026-04-10T08:41:55.360Z",
|
|
5
5
|
"buildEnvironment": {
|
|
6
|
-
"node": "
|
|
7
|
-
"platform": "
|
|
8
|
-
"arch": "
|
|
6
|
+
"node": "v20.20.2",
|
|
7
|
+
"platform": "linux",
|
|
8
|
+
"arch": "x64"
|
|
9
9
|
},
|
|
10
10
|
"git": {
|
|
11
|
-
"commit": "
|
|
12
|
-
"branch": "
|
|
11
|
+
"commit": "d195a996",
|
|
12
|
+
"branch": "master"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
15
15
|
"engines": {
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
"sha256": "dd82e7e2c23a2fcaefc0cb87a1a7931594d6a5f76b758f608c77063f5e8533cd"
|
|
107
107
|
},
|
|
108
108
|
"DeadLetterQueue.js": {
|
|
109
|
-
"size":
|
|
110
|
-
"sha256": "
|
|
109
|
+
"size": 19478,
|
|
110
|
+
"sha256": "d99676dc1750f740ed31c0df40e4ee3ad1c7e1ea2c9ac54d43885d4f88a07888"
|
|
111
111
|
},
|
|
112
112
|
"HealthMonitor.d.ts": {
|
|
113
113
|
"size": 1485,
|
|
@@ -178,16 +178,16 @@
|
|
|
178
178
|
"sha256": "3869f960c87260588e40941ff91bffcfa0757be7a04815fd28b57dd4840c51df"
|
|
179
179
|
},
|
|
180
180
|
"WorkerFactory.js": {
|
|
181
|
-
"size":
|
|
182
|
-
"sha256": "
|
|
181
|
+
"size": 105917,
|
|
182
|
+
"sha256": "11412e2889073bed28b16dbb2f7103c593181f364e47211bdc2beaf8a05985a5"
|
|
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": 14057,
|
|
190
|
+
"sha256": "29c4d961d14b9d78ee638b8ed3e0be55afc7edc3a6b7418a2c783339a4f7797a"
|
|
191
191
|
},
|
|
192
192
|
"WorkerMetrics.d.ts": {
|
|
193
193
|
"size": 3304,
|
|
@@ -213,14 +213,6 @@
|
|
|
213
213
|
"size": 7177,
|
|
214
214
|
"sha256": "59376b57b0e539bede2d659f0c995fca2ce21c671bc752cae99ab9788b71cd8f"
|
|
215
215
|
},
|
|
216
|
-
"WorkerShutdownDurableObject.d.ts": {
|
|
217
|
-
"size": 354,
|
|
218
|
-
"sha256": "521df11172067bc036bc7b95ff6adf40b7c594afa0454742963317ddfe776d37"
|
|
219
|
-
},
|
|
220
|
-
"WorkerShutdownDurableObject.js": {
|
|
221
|
-
"size": 1547,
|
|
222
|
-
"sha256": "9c7298133dfc4073fda80d3fe9a37ac00d31cacf500ce10c1dd43a70c3a8ddd7"
|
|
223
|
-
},
|
|
224
216
|
"WorkerVersioning.d.ts": {
|
|
225
217
|
"size": 2881,
|
|
226
218
|
"sha256": "a3f1f9e518e8a46201b181679bb5d7a484da7c021b4b7cfd5653cf98fe36e995"
|
|
@@ -229,17 +221,13 @@
|
|
|
229
221
|
"size": 10953,
|
|
230
222
|
"sha256": "8af20d462270e7044c6ea983821f5b6e6ce8a5caf39b6e8fefff07c9a0bf071e"
|
|
231
223
|
},
|
|
232
|
-
"build-manifest.json": {
|
|
233
|
-
"size": 19882,
|
|
234
|
-
"sha256": "d688d1b4a0aeb9e7992fc791d1ac11bf4d7df52fef74b2d3efff5801ce9ef1a5"
|
|
235
|
-
},
|
|
236
224
|
"config/workerConfig.d.ts": {
|
|
237
|
-
"size":
|
|
238
|
-
"sha256": "
|
|
225
|
+
"size": 282,
|
|
226
|
+
"sha256": "4671566a0cba372852c049ba66f7671ec19f5db38b0eaed1815eb532e7d58109"
|
|
239
227
|
},
|
|
240
228
|
"config/workerConfig.js": {
|
|
241
|
-
"size":
|
|
242
|
-
"sha256": "
|
|
229
|
+
"size": 3285,
|
|
230
|
+
"sha256": "c59a1d86d249c9841d83f5fe6ea3a0f0f79c82c4b986a2ecbbd2d5860b1847cd"
|
|
243
231
|
},
|
|
244
232
|
"createQueueWorker.d.ts": {
|
|
245
233
|
"size": 1031,
|
|
@@ -415,7 +403,7 @@
|
|
|
415
403
|
},
|
|
416
404
|
"index.js": {
|
|
417
405
|
"size": 2337,
|
|
418
|
-
"sha256": "
|
|
406
|
+
"sha256": "bd0aa624a51cf1bbcdfcd7d37cab797a1d76661f6a334679a3c627a2dd3621c3"
|
|
419
407
|
},
|
|
420
408
|
"queueMonitorHistory.d.ts": {
|
|
421
409
|
"size": 433,
|
|
@@ -544,22 +532,6 @@
|
|
|
544
532
|
"ui/types/worker-ui.js": {
|
|
545
533
|
"size": 94,
|
|
546
534
|
"sha256": "7e9f752c2a8eb29dab365b0c836bac90fa7d3567aaf961537d3aa782e85c884e"
|
|
547
|
-
},
|
|
548
|
-
"ui/workers/index.html": {
|
|
549
|
-
"size": 7940,
|
|
550
|
-
"sha256": "a71e384de568f720ff23bf5c90dca60cc97d30c0bbb4ccf5c3b026a8086381b4"
|
|
551
|
-
},
|
|
552
|
-
"ui/workers/main.js": {
|
|
553
|
-
"size": 60723,
|
|
554
|
-
"sha256": "8437771f28963e1b039bee0b1721a8e83a8c65bed19dbd89af0e37d5a2882bb4"
|
|
555
|
-
},
|
|
556
|
-
"ui/workers/styles.css": {
|
|
557
|
-
"size": 22652,
|
|
558
|
-
"sha256": "6de91f206251b0b69ca1a41b71b454b00e3b1213a9762abd8fd8f0ff0381556b"
|
|
559
|
-
},
|
|
560
|
-
"ui/workers/zintrust.svg": {
|
|
561
|
-
"size": 1035,
|
|
562
|
-
"sha256": "9b791269aad740b4191b0ae9f005b08bb28a3407a79a8ed38c11d225fa443f69"
|
|
563
535
|
}
|
|
564
536
|
}
|
|
565
537
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const WorkerConfig: Readonly<{
|
|
2
2
|
getWorkerBaseUrl: () => string;
|
|
3
3
|
}>;
|
|
4
|
+
export declare const resolveWorkerKeyPrefix: (value?: string | null) => string;
|
|
4
5
|
export declare const keyPrefix: () => string;
|
|
6
|
+
export declare const keyPrefixFor: (...segments: string[]) => string;
|
|
@@ -17,6 +17,7 @@ const resolveWorkerApiUrl = () => {
|
|
|
17
17
|
export const WorkerConfig = Object.freeze({
|
|
18
18
|
getWorkerBaseUrl: resolveWorkerApiUrl,
|
|
19
19
|
});
|
|
20
|
+
const LEGACY_REDIS_WORKER_PREFIX = 'zintrust:workers:';
|
|
20
21
|
const trimBoundaryUnderscores = (value) => {
|
|
21
22
|
let start = 0;
|
|
22
23
|
let end = value.length;
|
|
@@ -36,13 +37,59 @@ const normalizeAppName = (value) => {
|
|
|
36
37
|
const normalized = trimBoundaryUnderscores(collapsedUnderscores);
|
|
37
38
|
return normalized === '' ? 'zintrust' : normalized;
|
|
38
39
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const trimBoundaryColons = (value) => {
|
|
41
|
+
let start = 0;
|
|
42
|
+
let end = value.length;
|
|
43
|
+
while (start < end && value.charAt(start) === ':') {
|
|
44
|
+
start += 1;
|
|
43
45
|
}
|
|
46
|
+
while (end > start && value.charAt(end - 1) === ':') {
|
|
47
|
+
end -= 1;
|
|
48
|
+
}
|
|
49
|
+
return value.slice(start, end);
|
|
50
|
+
};
|
|
51
|
+
const defaultKeyPrefix = () => {
|
|
44
52
|
const appName = typeof appConfig.name === 'string' && appConfig.name.trim() !== ''
|
|
45
53
|
? appConfig.name
|
|
46
54
|
: Env.get('APP_NAME', 'zintrust');
|
|
47
55
|
return `${normalizeAppName(appName)}_zintrust:workers:`;
|
|
48
56
|
};
|
|
57
|
+
const isLegacyWorkerPrefix = (value) => {
|
|
58
|
+
if (value === LEGACY_REDIS_WORKER_PREFIX)
|
|
59
|
+
return true;
|
|
60
|
+
if (value.startsWith('worker_'))
|
|
61
|
+
return true;
|
|
62
|
+
return value.includes(':workers:_worker_');
|
|
63
|
+
};
|
|
64
|
+
const normalizeConfiguredKeyPrefix = (value) => {
|
|
65
|
+
if (typeof value !== 'string')
|
|
66
|
+
return undefined;
|
|
67
|
+
const trimmed = value.trim();
|
|
68
|
+
if (trimmed === '')
|
|
69
|
+
return undefined;
|
|
70
|
+
if (isLegacyWorkerPrefix(trimmed)) {
|
|
71
|
+
return defaultKeyPrefix();
|
|
72
|
+
}
|
|
73
|
+
return trimmed;
|
|
74
|
+
};
|
|
75
|
+
const appendPrefixSegment = (base, segment) => {
|
|
76
|
+
const normalizedSegment = trimBoundaryColons(segment.trim());
|
|
77
|
+
if (normalizedSegment === '')
|
|
78
|
+
return base;
|
|
79
|
+
const normalizedBase = trimBoundaryColons(base);
|
|
80
|
+
if (normalizedBase === '') {
|
|
81
|
+
return `${normalizedSegment}:`;
|
|
82
|
+
}
|
|
83
|
+
return `${normalizedBase}:${normalizedSegment}:`;
|
|
84
|
+
};
|
|
85
|
+
export const resolveWorkerKeyPrefix = (value) => {
|
|
86
|
+
return (normalizeConfiguredKeyPrefix(value) ??
|
|
87
|
+
normalizeConfiguredKeyPrefix(Env.get('WORKER_PERSISTENCE_REDIS_KEY_PREFIX', '')) ??
|
|
88
|
+
defaultKeyPrefix());
|
|
89
|
+
};
|
|
90
|
+
export const keyPrefix = () => {
|
|
91
|
+
return resolveWorkerKeyPrefix();
|
|
92
|
+
};
|
|
93
|
+
export const keyPrefixFor = (...segments) => {
|
|
94
|
+
return segments.reduce((prefix, segment) => appendPrefixSegment(prefix, segment), keyPrefix());
|
|
95
|
+
};
|
package/package.json
CHANGED
package/src/DeadLetterQueue.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { ErrorFactory, Logger, createRedisConnection, type RedisConfig } from '@zintrust/core';
|
|
8
|
-
import {
|
|
8
|
+
import { keyPrefixFor } from './config/workerConfig';
|
|
9
9
|
|
|
10
10
|
type RedisConnection = ReturnType<typeof createRedisConnection>;
|
|
11
11
|
|
|
@@ -74,11 +74,11 @@ export type DLQStats = {
|
|
|
74
74
|
|
|
75
75
|
// Redis key prefixes - using workers package prefix system
|
|
76
76
|
const getDLQPrefix = (): string => {
|
|
77
|
-
return
|
|
77
|
+
return keyPrefixFor('dlq');
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
const getAuditPrefix = (): string => {
|
|
81
|
-
return
|
|
81
|
+
return keyPrefixFor('dlq', 'audit');
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
// Internal state
|
package/src/WorkerFactory.ts
CHANGED
|
@@ -46,7 +46,7 @@ import { ResourceMonitor } from './ResourceMonitor';
|
|
|
46
46
|
import { WorkerMetrics } from './WorkerMetrics';
|
|
47
47
|
import { WorkerRegistry, type WorkerInstance as RegistryWorkerInstance } from './WorkerRegistry';
|
|
48
48
|
import { WorkerVersioning } from './WorkerVersioning';
|
|
49
|
-
import {
|
|
49
|
+
import { resolveWorkerKeyPrefix } from './config/workerConfig';
|
|
50
50
|
import { recordQueueMonitorJob } from './queueMonitorHistory';
|
|
51
51
|
import {
|
|
52
52
|
DbWorkerStore,
|
|
@@ -2166,7 +2166,7 @@ const normalizeExplicitPersistence = (
|
|
|
2166
2166
|
return {
|
|
2167
2167
|
driver: 'redis',
|
|
2168
2168
|
redis: persistence.redis,
|
|
2169
|
-
keyPrefix: keyPrefix
|
|
2169
|
+
keyPrefix: resolveWorkerKeyPrefix(persistence.keyPrefix),
|
|
2170
2170
|
};
|
|
2171
2171
|
}
|
|
2172
2172
|
|
|
@@ -2210,7 +2210,7 @@ const resolvePersistenceConfig = (
|
|
|
2210
2210
|
env: true,
|
|
2211
2211
|
db: persistenceDbOverride ? 'WORKER_PERSISTENCE_REDIS_DB' : 'REDIS_QUEUE_DB',
|
|
2212
2212
|
},
|
|
2213
|
-
keyPrefix:
|
|
2213
|
+
keyPrefix: resolveWorkerKeyPrefix(),
|
|
2214
2214
|
};
|
|
2215
2215
|
}
|
|
2216
2216
|
|
|
@@ -2270,7 +2270,7 @@ const resolveWorkerStore = async (config: WorkerFactoryConfig): Promise<WorkerSt
|
|
|
2270
2270
|
'Worker persistence requires redis config (persistence.redis or infrastructure.redis)',
|
|
2271
2271
|
'infrastructure.persistence.redis'
|
|
2272
2272
|
);
|
|
2273
|
-
const key_prefix = persistence.keyPrefix
|
|
2273
|
+
const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
|
|
2274
2274
|
logRedisPersistenceConfig(redisConfig, key_prefix, 'resolveWorkerStore');
|
|
2275
2275
|
const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
|
|
2276
2276
|
next = RedisWorkerStore.create(client, key_prefix);
|
|
@@ -2324,7 +2324,7 @@ const createWorkerStore = async (persistence: WorkerPersistenceConfig): Promise<
|
|
|
2324
2324
|
'Worker persistence requires redis config (persistence.redis or REDIS_* env values)',
|
|
2325
2325
|
'persistence.redis'
|
|
2326
2326
|
);
|
|
2327
|
-
const key_prefix = persistence.keyPrefix
|
|
2327
|
+
const key_prefix = resolveWorkerKeyPrefix(persistence.keyPrefix);
|
|
2328
2328
|
logRedisPersistenceConfig(redisConfig, key_prefix, 'createWorkerStore');
|
|
2329
2329
|
const client = createRedisConnection(redisConfig, 3, { subsystem: 'worker-persistence' });
|
|
2330
2330
|
return RedisWorkerStore.create(client, key_prefix);
|
package/src/WorkerInit.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { ResourceMonitor } from './ResourceMonitor';
|
|
|
13
13
|
import type { WorkerPersistenceConfig } from './WorkerFactory';
|
|
14
14
|
import { WorkerFactory } from './WorkerFactory';
|
|
15
15
|
import { WorkerShutdown } from './WorkerShutdown';
|
|
16
|
-
import {
|
|
16
|
+
import { resolveWorkerKeyPrefix } from './config/workerConfig';
|
|
17
17
|
|
|
18
18
|
// ============================================================================
|
|
19
19
|
// Types
|
|
@@ -109,7 +109,7 @@ function initializeResourceMonitoring(
|
|
|
109
109
|
|
|
110
110
|
const getPersistenceOverride = (driver: string): WorkerPersistenceConfig => {
|
|
111
111
|
if (driver === 'redis') {
|
|
112
|
-
return { driver: 'redis', keyPrefix:
|
|
112
|
+
return { driver: 'redis', keyPrefix: resolveWorkerKeyPrefix() };
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
if (driver === 'memory') {
|
|
@@ -24,6 +24,8 @@ export const WorkerConfig = Object.freeze({
|
|
|
24
24
|
getWorkerBaseUrl: resolveWorkerApiUrl,
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
const LEGACY_REDIS_WORKER_PREFIX = 'zintrust:workers:';
|
|
28
|
+
|
|
27
29
|
const trimBoundaryUnderscores = (value: string): string => {
|
|
28
30
|
let start = 0;
|
|
29
31
|
let end = value.length;
|
|
@@ -48,13 +50,22 @@ const normalizeAppName = (value: string): string => {
|
|
|
48
50
|
return normalized === '' ? 'zintrust' : normalized;
|
|
49
51
|
};
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
const trimBoundaryColons = (value: string): string => {
|
|
54
|
+
let start = 0;
|
|
55
|
+
let end = value.length;
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
while (start < end && value.charAt(start) === ':') {
|
|
58
|
+
start += 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
while (end > start && value.charAt(end - 1) === ':') {
|
|
62
|
+
end -= 1;
|
|
56
63
|
}
|
|
57
64
|
|
|
65
|
+
return value.slice(start, end);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const defaultKeyPrefix = (): string => {
|
|
58
69
|
const appName =
|
|
59
70
|
typeof appConfig.name === 'string' && appConfig.name.trim() !== ''
|
|
60
71
|
? appConfig.name
|
|
@@ -62,3 +73,50 @@ export const keyPrefix = (): string => {
|
|
|
62
73
|
|
|
63
74
|
return `${normalizeAppName(appName)}_zintrust:workers:`;
|
|
64
75
|
};
|
|
76
|
+
|
|
77
|
+
const isLegacyWorkerPrefix = (value: string): boolean => {
|
|
78
|
+
if (value === LEGACY_REDIS_WORKER_PREFIX) return true;
|
|
79
|
+
if (value.startsWith('worker_')) return true;
|
|
80
|
+
return value.includes(':workers:_worker_');
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const normalizeConfiguredKeyPrefix = (value: string | undefined | null): string | undefined => {
|
|
84
|
+
if (typeof value !== 'string') return undefined;
|
|
85
|
+
|
|
86
|
+
const trimmed = value.trim();
|
|
87
|
+
if (trimmed === '') return undefined;
|
|
88
|
+
|
|
89
|
+
if (isLegacyWorkerPrefix(trimmed)) {
|
|
90
|
+
return defaultKeyPrefix();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return trimmed;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const appendPrefixSegment = (base: string, segment: string): string => {
|
|
97
|
+
const normalizedSegment = trimBoundaryColons(segment.trim());
|
|
98
|
+
if (normalizedSegment === '') return base;
|
|
99
|
+
|
|
100
|
+
const normalizedBase = trimBoundaryColons(base);
|
|
101
|
+
if (normalizedBase === '') {
|
|
102
|
+
return `${normalizedSegment}:`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return `${normalizedBase}:${normalizedSegment}:`;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const resolveWorkerKeyPrefix = (value?: string | null): string => {
|
|
109
|
+
return (
|
|
110
|
+
normalizeConfiguredKeyPrefix(value) ??
|
|
111
|
+
normalizeConfiguredKeyPrefix(Env.get('WORKER_PERSISTENCE_REDIS_KEY_PREFIX', '')) ??
|
|
112
|
+
defaultKeyPrefix()
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const keyPrefix = (): string => {
|
|
117
|
+
return resolveWorkerKeyPrefix();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const keyPrefixFor = (...segments: string[]): string => {
|
|
121
|
+
return segments.reduce((prefix, segment) => appendPrefixSegment(prefix, segment), keyPrefix());
|
|
122
|
+
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type DurableObjectState = {
|
|
2
|
-
storage: {
|
|
3
|
-
get: (key: string) => Promise<unknown>;
|
|
4
|
-
put: (key: string, value: unknown) => Promise<void>;
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export declare class ZinTrustWorkerShutdownDurableObject {
|
|
8
|
-
private readonly state;
|
|
9
|
-
constructor(state: DurableObjectState);
|
|
10
|
-
fetch(request: Request): Promise<Response>;
|
|
11
|
-
}
|
|
12
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@zintrust/core';
|
|
2
|
-
const loadState = async (state) => {
|
|
3
|
-
const stored = (await state.storage.get('shutdown'));
|
|
4
|
-
return stored ?? { shuttingDown: false };
|
|
5
|
-
};
|
|
6
|
-
const saveState = async (state, value) => {
|
|
7
|
-
await state.storage.put('shutdown', value);
|
|
8
|
-
};
|
|
9
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
10
|
-
export class ZinTrustWorkerShutdownDurableObject {
|
|
11
|
-
state;
|
|
12
|
-
constructor(state) {
|
|
13
|
-
this.state = state;
|
|
14
|
-
}
|
|
15
|
-
async fetch(request) {
|
|
16
|
-
const url = new URL(request.url);
|
|
17
|
-
const path = url.pathname;
|
|
18
|
-
if (request.method === 'GET' && path === '/status') {
|
|
19
|
-
const current = await loadState(this.state);
|
|
20
|
-
return new Response(JSON.stringify(current), {
|
|
21
|
-
status: 200,
|
|
22
|
-
headers: { 'content-type': 'application/json' },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (request.method === 'POST' && path === '/shutdown') {
|
|
26
|
-
const payload = (await request.json().catch(() => ({})));
|
|
27
|
-
const next = {
|
|
28
|
-
shuttingDown: true,
|
|
29
|
-
startedAt: new Date().toISOString(),
|
|
30
|
-
reason: payload.reason ?? 'manual',
|
|
31
|
-
};
|
|
32
|
-
await saveState(this.state, next);
|
|
33
|
-
Logger.info('Worker shutdown requested via Durable Object', next);
|
|
34
|
-
return new Response(JSON.stringify({ ok: true }), {
|
|
35
|
-
status: 202,
|
|
36
|
-
headers: { 'content-type': 'application/json' },
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return new Response('Not Found', { status: 404 });
|
|
40
|
-
}
|
|
41
|
-
}
|