@nsshunt/stsrunnerframework 1.0.199 → 2.0.1

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.
Files changed (44) hide show
  1. package/README.md +1059 -1
  2. package/dist/stsrunnerframework.mjs +8263 -4103
  3. package/dist/stsrunnerframework.mjs.map +1 -1
  4. package/dist/stsrunnerframework.umd.js +8288 -4117
  5. package/dist/stsrunnerframework.umd.js.map +1 -1
  6. package/package.json +4 -4
  7. package/types/abstractRunnerExecutionWorker.d.ts +194 -0
  8. package/types/abstractRunnerExecutionWorker.d.ts.map +1 -0
  9. package/types/archiveManager.d.ts +172 -0
  10. package/types/archiveManager.d.ts.map +1 -0
  11. package/types/asyncRunnerInstanceManager.d.ts +108 -0
  12. package/types/asyncRunnerInstanceManager.d.ts.map +1 -0
  13. package/types/commonTypes.d.ts +115 -35
  14. package/types/commonTypes.d.ts.map +1 -1
  15. package/types/index.d.ts +1 -1
  16. package/types/index.d.ts.map +1 -1
  17. package/types/messageBroker.d.ts +324 -0
  18. package/types/messageBroker.d.ts.map +1 -0
  19. package/types/runnerInstance.d.ts +245 -0
  20. package/types/runnerInstance.d.ts.map +1 -0
  21. package/types/runnerLifecycleManager.d.ts +210 -0
  22. package/types/runnerLifecycleManager.d.ts.map +1 -0
  23. package/types/telemetryProcessor.d.ts +67 -0
  24. package/types/telemetryProcessor.d.ts.map +1 -1
  25. package/types/testing/mockedWorkerTestRunner01.d.ts +129 -2
  26. package/types/testing/mockedWorkerTestRunner01.d.ts.map +1 -1
  27. package/types/testing/testCase01.d.ts +222 -2
  28. package/types/testing/testCase01.d.ts.map +1 -1
  29. package/types/testing/testCase02.d.ts +206 -2
  30. package/types/testing/testCase02.d.ts.map +1 -1
  31. package/types/testing/wmwokerProcess.test.d.ts +1 -0
  32. package/types/testing/wmwokerProcess2.test.d.ts +1 -0
  33. package/types/workerCommandCoordinator.d.ts +152 -0
  34. package/types/workerCommandCoordinator.d.ts.map +1 -0
  35. package/types/workerInstance.d.ts +340 -16
  36. package/types/workerInstance.d.ts.map +1 -1
  37. package/types/workerInstanceMannager.d.ts +170 -0
  38. package/types/workerInstanceMannager.d.ts.map +1 -0
  39. package/types/workerManager.d.ts +335 -24
  40. package/types/workerManager.d.ts.map +1 -1
  41. package/types/workerRegistry.d.ts +251 -0
  42. package/types/workerRegistry.d.ts.map +1 -0
  43. package/types/workerStateSynchroniser.d.ts +161 -0
  44. package/types/workerStateSynchroniser.d.ts.map +1 -0
@@ -1,53 +1,364 @@
1
- import { IWorkerEx, IRunner, IRunnerEx, IRunnerOptions, IWorkerManagerOptions, IWorkerFactory, IWorkerOptions, IRunnerState, IWorker, IExecuteWorkerActionResult, IExecuteRunnerActionResult, IWorkers, IRunnerSearchFilters } from './commonTypes';
2
- export declare class STSWorkerManager {
1
+
2
+ /**
3
+ * STSWorkerManager
4
+ * ================
5
+ *
6
+ * Top-level orchestration class for the worker/runner framework.
7
+ *
8
+ * This class is the main manager-side entry point used to:
9
+ *
10
+ * - create and register workers
11
+ * - create and register runners inside workers
12
+ * - coordinate worker-wide and runner-specific commands
13
+ * - synchronise live worker/runner state from worker runtimes
14
+ * - expose archived runner history
15
+ * - coordinate supporting infrastructure such as:
16
+ * - message brokering
17
+ * - worker registry
18
+ * - archive management
19
+ * - runner lifecycle processing
20
+ * - worker state synchronisation
21
+ * - worker command coordination
22
+ *
23
+ * Architectural role
24
+ * ------------------
25
+ * `STSWorkerManager` acts primarily as:
26
+ *
27
+ * - a composition root
28
+ * - a façade
29
+ * - a coordinator entry point
30
+ *
31
+ * It does **not** directly implement all worker or runner behaviour itself.
32
+ * Instead, it composes several more focused collaborators:
33
+ *
34
+ * - {@link WorkerRegistry}
35
+ * - {@link STSMessageBroker}
36
+ * - {@link AsyncRunnerInstanceManager}
37
+ * - {@link ArchiveManager}
38
+ * - {@link WorkerInstanceManager}
39
+ * - {@link RunnerLifecycleManager}
40
+ * - {@link WorkerStateSynchroniser}
41
+ * - {@link WorkerCommandCoordinator}
42
+ *
43
+ * High-level lifecycle
44
+ * --------------------
45
+ * 1. Construct manager and all supporting services
46
+ * 2. Add workers
47
+ * 3. Add runners to workers
48
+ * 4. Start/pause/resume/execute/reset/update/terminate workers or runners
49
+ * 5. Receive telemetry and state changes through broker + lifecycle manager
50
+ * 6. Archive retired runners through archive manager
51
+ * 7. Synchronise state on demand through worker state synchroniser
52
+ *
53
+ * Notes
54
+ * -----
55
+ * - This class owns the manager id.
56
+ * - This class owns the shared registry and shared service instances.
57
+ * - Most public methods are intentionally thin façade methods delegating to
58
+ * more specialised collaborators.
59
+ */
60
+ import { IWorkerEx, IRunner, IRunnerEx, IRunnerOptions, IWorkerManagerOptions, IWorkerFactory, IWorkerOptions, IRunnerState, IExecuteWorkerActionResult, IExecuteRunnerActionResult, IWorkers, IRunnerSearchFilters, ISTSWorkerManager, IWorkerCore } from './commonTypes';
61
+ /**
62
+ * Main manager/coordinator for workers and runners.
63
+ *
64
+ * This class implements {@link ISTSWorkerManager} and serves as the primary
65
+ * public API for interacting with the framework from the manager side.
66
+ */
67
+ export declare class STSWorkerManager implements ISTSWorkerManager {
3
68
  #private;
69
+ /**
70
+ * Construct a new worker manager.
71
+ *
72
+ * Behaviour:
73
+ * - generates a manager id
74
+ * - stores supplied options (or initialises an empty options object)
75
+ * - constructs all shared supporting services
76
+ * - starts the archive processing loop
77
+ *
78
+ * Constructed collaborators:
79
+ * - worker registry
80
+ * - optional instrumentation controller reference
81
+ * - message broker
82
+ * - async runner instance manager
83
+ * - archive manager
84
+ * - worker instance manager
85
+ * - runner lifecycle manager
86
+ * - worker state synchroniser
87
+ * - worker command coordinator
88
+ *
89
+ * @param options Optional worker-manager runtime configuration.
90
+ */
4
91
  constructor(options?: IWorkerManagerOptions);
5
- GetRunnerMetadataCopyNoHistory(runnerEx: IRunnerEx): IRunner;
6
- GetRunnerMetadataCopy(runnerEx: IRunnerEx): IRunner;
7
- GetRunnerMetadataPartialCopy(runnerEx: IRunnerEx): Partial<IRunner>;
8
- GetWorkerMetadataCopy(workerEx: IWorkerEx): IWorker;
9
- GetWorkerMetadataPartialCopyByRunnerState(workerEx: IWorkerEx, states: IRunnerState[]): Partial<IWorker>;
10
92
  /**
11
- * @returns Return the WorkerManager Id, i.e. this Id.
93
+ * Get archived runner snapshots filtered by the supplied search criteria.
94
+ *
95
+ * Delegates to the shared {@link ArchiveManager}.
96
+ *
97
+ * Supported filters are defined by {@link IRunnerSearchFilters}.
98
+ *
99
+ * @param runnerSearchFilters Archive search/filter criteria.
100
+ * @returns Matching archived runners.
101
+ */
102
+ GetArchiveList: (runnerSearchFilters: IRunnerSearchFilters) => Promise<IRunner[]>;
103
+ /**
104
+ * Get the unique id for this worker manager instance.
105
+ *
106
+ * @returns Worker manager id.
12
107
  */
13
108
  get id(): string;
14
- GetWorkersMetadataCopyPostSync: () => Promise<IWorkers>;
15
109
  /**
16
- * Only include runners that are in the specified states.
17
- * @param states Use [] to include all runners irrespective of state.
18
- * @returns IWorkers (partial copy)
110
+ * Resolve the worker factory that should be used for worker creation.
111
+ *
112
+ * Behaviour:
113
+ * - if an explicit `useWorkerFactory` is supplied, it is used
114
+ * - otherwise falls back to the default factory configured in manager options
115
+ *
116
+ * @param useWorkerFactory Optional explicit factory override.
117
+ * @returns Resolved worker factory.
19
118
  */
20
- GetWorkersMetadataPartialCopyByRunnerStatePostSync: (states: IRunnerState[]) => Promise<IWorkers>;
21
- get WorkersEx(): Record<string, IWorkerEx>;
119
+ private ResolveWorkerFactory;
22
120
  /**
23
- * Filter by plan and/or tag. Leave blank to not use in filter.
24
- * @param runnerSearchFilters
25
- * @returns
121
+ * Create a manager-side worker instance and wire its initial message port.
122
+ *
123
+ * Behaviour:
124
+ * - creates the manager-side {@link IWorkerEx} using {@link WorkerInstanceManager}
125
+ * - optionally writes instrumentation log output
126
+ * - logs worker creation details
127
+ * - bootstraps the worker's dedicated message port through the broker
128
+ *
129
+ * Notes:
130
+ * - this method does not register the worker in the registry
131
+ * - this method does not attach system/runtime worker event handlers
132
+ * - both are handled by the caller (`AddWorker`)
133
+ *
134
+ * @param workerOptions Worker-specific runtime options.
135
+ * @param workerFactory Factory used to create the actual worker.
136
+ * @param port1 Manager-side message port.
137
+ * @param port2 Worker-side message port to transfer into the worker runtime.
138
+ * @returns Newly created manager-side worker instance.
139
+ */
140
+ private CreateAndWireWorker;
141
+ /**
142
+ * Create and register a new worker.
143
+ *
144
+ * Behaviour:
145
+ * - resolves the worker factory
146
+ * - creates a new dedicated message channel (`port1`, `port2`)
147
+ * - creates and bootstraps the manager-side worker instance
148
+ * - adds the worker to the live worker registry
149
+ * - attaches native/system worker event handlers for real workers
150
+ * - attaches broker message-port listener for unsolicited messages
151
+ * - returns the live manager-side worker instance
152
+ *
153
+ * Notes:
154
+ * - mocked workers do not get system/runtime worker event wiring
155
+ * - unsolicited messages from the worker are processed by a handler produced
156
+ * by {@link RunnerLifecycleManager}
157
+ *
158
+ * @param workerOptions Worker-specific runtime options.
159
+ * @param useWorkerFactory Optional explicit worker factory override.
160
+ * @returns Newly created live worker instance.
161
+ * @throws Re-throws unexpected creation/wiring errors after logging.
26
162
  */
27
- GetArchiveList: (runnerSearchFilters: IRunnerSearchFilters) => Promise<IRunner[]>;
28
- GetWorkerMetadataCopyPosySync: (workerId: string) => Promise<IWorker>;
29
- GetRunnerMetadataCopyPostSync: (workerId: string, runnerId: string) => Promise<IRunner>;
30
163
  AddWorker: (workerOptions: IWorkerOptions, useWorkerFactory?: IWorkerFactory) => Promise<IWorkerEx>;
164
+ /**
165
+ * Create and add a new runner to an existing worker.
166
+ *
167
+ * Behaviour:
168
+ * - creates a new manager-side live runner instance via {@link AsyncRunnerInstanceManager}
169
+ * - adds the runner to the live worker registry
170
+ * - sends `AddRunner` to the underlying worker via the message broker
171
+ * - emits optional instrumentation logging for the new runner
172
+ * - returns the live manager-side runner instance
173
+ *
174
+ * Notes:
175
+ * - the runner is added to the manager-side registry before the brokered add command
176
+ * completes
177
+ * - the worker runtime is expected to create its own corresponding executable runner
178
+ * when it receives the `AddRunner` command
179
+ *
180
+ * @param stsWorkerEx Target worker that will own the runner.
181
+ * @param runnerOptions Runner-specific runtime options.
182
+ * @returns Newly created live runner instance.
183
+ * @throws Re-throws unexpected errors after logging.
184
+ */
31
185
  AddRunnerToWorker: (stsWorkerEx: IWorkerEx, runnerOptions: IRunnerOptions) => Promise<IRunnerEx>;
32
- GetNextAvailableWorker: () => IWorkerEx | null;
33
- GetBusiestWorker: () => IWorkerEx | null;
34
- get Options(): IWorkerManagerOptions;
35
- set Options(options: IWorkerManagerOptions);
186
+ /**
187
+ * Get the current worker-manager options object.
188
+ *
189
+ * @returns Current worker-manager options.
190
+ */
191
+ get options(): IWorkerManagerOptions;
192
+ /**
193
+ * Replace the current worker-manager options.
194
+ *
195
+ * Notes:
196
+ * - this updates the stored options object
197
+ * - already-created collaborators are not rebuilt automatically
198
+ *
199
+ * @param options New worker-manager options.
200
+ */
201
+ SetOptions(options: IWorkerManagerOptions): void;
202
+ /**
203
+ * Start one or more workers.
204
+ *
205
+ * Delegates to {@link WorkerCommandCoordinator}.
206
+ *
207
+ * @param workerIds Worker ids to target. Use `[]` for all workers if supported by the registry/coordinator.
208
+ * @returns Worker-level aggregated execution results.
209
+ */
36
210
  StartWorkers: (workerIds: string[]) => Promise<IExecuteWorkerActionResult[]>;
211
+ /**
212
+ * Stop one or more workers.
213
+ *
214
+ * @param workerIds Worker ids to target.
215
+ * @returns Worker-level aggregated execution results.
216
+ */
37
217
  StopWorkers: (workerIds: string[]) => Promise<IExecuteWorkerActionResult[]>;
218
+ /**
219
+ * Pause one or more workers.
220
+ *
221
+ * @param workerIds Worker ids to target.
222
+ * @returns Worker-level aggregated execution results.
223
+ */
38
224
  PauseWorkers: (workerIds: string[]) => Promise<IExecuteWorkerActionResult[]>;
225
+ /**
226
+ * Resume one or more workers.
227
+ *
228
+ * @param workerIds Worker ids to target.
229
+ * @returns Worker-level aggregated execution results.
230
+ */
39
231
  ResumeWorkers: (workerIds: string[]) => Promise<IExecuteWorkerActionResult[]>;
232
+ /**
233
+ * Execute one or more workers.
234
+ *
235
+ * @param workerIds Worker ids to target.
236
+ * @returns Worker-level aggregated execution results.
237
+ */
40
238
  ExecuteWorkers: (workerIds: string[]) => Promise<IExecuteWorkerActionResult[]>;
239
+ /**
240
+ * Reset one or more workers.
241
+ *
242
+ * @param workerIds Worker ids to target.
243
+ * @returns Worker-level aggregated execution results.
244
+ */
41
245
  ResetWorkers: (workerIds: string[]) => Promise<IExecuteWorkerActionResult[]>;
246
+ /**
247
+ * Terminate one or more workers.
248
+ *
249
+ * @param workerIds Worker ids to target.
250
+ * @returns Worker-level aggregated execution results.
251
+ */
42
252
  TerminateWorkers: (workerIds: string[]) => Promise<IExecuteWorkerActionResult[]>;
253
+ /**
254
+ * Update runner options across one or more workers.
255
+ *
256
+ * @param workerIds Worker ids to target.
257
+ * @param runnerOptions Partial runner option updates to apply.
258
+ * @returns Worker-level aggregated execution results.
259
+ */
43
260
  UpdateWorkers: (workerIds: string[], runnerOptions: Partial<IRunnerOptions>) => Promise<IExecuteWorkerActionResult[]>;
261
+ /**
262
+ * Stop one or more runners within a worker.
263
+ *
264
+ * @param workerId Owning worker id.
265
+ * @param runnerIds Runner ids to target.
266
+ * @returns Per-runner execution results.
267
+ */
44
268
  StopRunners: (workerId: string, runnerIds: string[]) => Promise<IExecuteRunnerActionResult[]>;
269
+ /**
270
+ * Start one or more runners within a worker.
271
+ *
272
+ * @param workerId Owning worker id.
273
+ * @param runnerIds Runner ids to target.
274
+ * @returns Per-runner execution results.
275
+ */
45
276
  StartRunners: (workerId: string, runnerIds: string[]) => Promise<IExecuteRunnerActionResult[]>;
277
+ /**
278
+ * Pause one or more runners within a worker.
279
+ *
280
+ * @param workerId Owning worker id.
281
+ * @param runnerIds Runner ids to target.
282
+ * @returns Per-runner execution results.
283
+ */
46
284
  PauseRunners: (workerId: string, runnerIds: string[]) => Promise<IExecuteRunnerActionResult[]>;
285
+ /**
286
+ * Resume one or more runners within a worker.
287
+ *
288
+ * @param workerId Owning worker id.
289
+ * @param runnerIds Runner ids to target.
290
+ * @returns Per-runner execution results.
291
+ */
47
292
  ResumeRunners: (workerId: string, runnerIds: string[]) => Promise<IExecuteRunnerActionResult[]>;
293
+ /**
294
+ * Execute one or more runners within a worker.
295
+ *
296
+ * @param workerId Owning worker id.
297
+ * @param runnerIds Runner ids to target.
298
+ * @returns Per-runner execution results.
299
+ */
48
300
  ExecuteRunners: (workerId: string, runnerIds: string[]) => Promise<IExecuteRunnerActionResult[]>;
301
+ /**
302
+ * Reset one or more runners within a worker.
303
+ *
304
+ * @param workerId Owning worker id.
305
+ * @param runnerIds Runner ids to target.
306
+ * @returns Per-runner execution results.
307
+ */
49
308
  ResetRunners: (workerId: string, runnerIds: string[]) => Promise<IExecuteRunnerActionResult[]>;
309
+ /**
310
+ * Terminate one or more runners within a worker.
311
+ *
312
+ * @param workerId Owning worker id.
313
+ * @param runnerIds Runner ids to target.
314
+ * @returns Per-runner execution results.
315
+ */
50
316
  TerminateRunners: (workerId: string, runnerIds: string[]) => Promise<IExecuteRunnerActionResult[]>;
317
+ /**
318
+ * Update one or more runners within a worker.
319
+ *
320
+ * @param workerId Owning worker id.
321
+ * @param runnerIds Runner ids to target.
322
+ * @param runnerOptions Partial runner option updates.
323
+ * @returns Per-runner execution results.
324
+ */
51
325
  UpdateRunners: (workerId: string, runnerIds: string[], runnerOptions: Partial<IRunnerOptions>) => Promise<IExecuteRunnerActionResult[]>;
326
+ /**
327
+ * Terminate manager-owned background processing.
328
+ *
329
+ * Current behaviour:
330
+ * - stops the archive manager loop
331
+ *
332
+ * Notes:
333
+ * - this does not automatically terminate all workers
334
+ * - callers should explicitly terminate workers first if desired
335
+ */
336
+ Terminate(): void;
337
+ /**
338
+ * Get the full current workers model.
339
+ *
340
+ * Behaviour:
341
+ * - synchronises live state from worker runtimes through {@link WorkerStateSynchroniser}
342
+ * - returns the fully populated serialisable workers model
343
+ *
344
+ * @returns Full worker/runners model.
345
+ */
346
+ GetWorkers: () => Promise<IWorkers>;
347
+ /**
348
+ * Get the reduced/core workers model.
349
+ *
350
+ * Behaviour:
351
+ * - synchronises live state from worker runtimes through {@link WorkerStateSynchroniser}
352
+ * - returns a reduced/core worker model, optionally filtered by runner state
353
+ *
354
+ * Runner state filtering:
355
+ * - `undefined` => include all runners
356
+ * - `[]` => include all runners
357
+ * - populated array => include only runners whose state matches
358
+ *
359
+ * @param states Optional runner-state filter.
360
+ * @returns Reduced/core workers model.
361
+ */
362
+ GetWorkersCore: (states?: IRunnerState[]) => Promise<Record<string, IWorkerCore>>;
52
363
  }
53
364
  //# sourceMappingURL=workerManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workerManager.d.ts","sourceRoot":"","sources":["../src/workerManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,SAAS,EAAE,OAAO,EAAE,SAAS,EACA,cAAc,EAC3C,qBAAqB,EAAE,cAAc,EACrC,cAAc,EAAE,YAAY,EAC5B,OAAO,EAAY,0BAA0B,EAAE,0BAA0B,EAAE,QAAQ,EACnF,oBAAoB,EACvB,MAAM,eAAe,CAAA;AAgBtB,qBAAa,gBAAgB;;gBAWb,OAAO,CAAC,EAAE,qBAAqB;IAkD3C,8BAA8B,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO;IAkB5D,qBAAqB,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO;IAanD,4BAA4B,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAmBnE,qBAAqB,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO;IAmBnD,yCAAyC,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA6FxG;;OAEG;IACH,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,8BAA8B,QAAa,OAAO,CAAC,QAAQ,CAAC,CAa3D;IAKD;;;;OAIG;IACH,kDAAkD,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gB,GAAU,UAAU,MAAM,EAAE,WAAW,MAAM,EAAE,KAAG,OAAO,CAAC,0BAA0B,EAAE,CAAC,CAErG;IAEF;;;;;;;OAOG;IACH,aAAa,GACT,UAAU,MAAM,EAChB,WAAW,MAAM,EAAE,EACnB,eAAe,OAAO,CAAC,cAAc,CAAC,KACvC,OAAO,CAAC,0BAA0B,EAAE,CAAC,CAOtC;IAEF;;;;;;;;;OASG;IACH,SAAS,IAAI,IAAI;IAIjB;;;;;;;;OAQG;IACH,UAAU,QAAa,OAAO,CAAC,QAAQ,CAAC,CAEtC;IAEF;;;;;;;;;;;;;;OAcG;IACH,cAAc,GAAU,SAAS,YAAY,EAAE,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAEpF;CACL"}
@@ -0,0 +1,251 @@
1
+
2
+ /**
3
+ * WorkerRegistry
4
+ * ==============
5
+ *
6
+ * Central in-memory registry for all live manager-side workers and runners.
7
+ *
8
+ * This class is responsible for maintaining the manager-side runtime graph of:
9
+ *
10
+ * - workers (`IWorkerEx`)
11
+ * - runners (`IRunnerEx`) owned by those workers
12
+ *
13
+ * Architectural role
14
+ * ------------------
15
+ * `WorkerRegistry` acts as the single source of truth for the current live
16
+ * manager-side object model.
17
+ *
18
+ * Other services use this registry to:
19
+ *
20
+ * - locate workers
21
+ * - locate runners within workers
22
+ * - add/remove workers and runners
23
+ * - generate serialisable worker maps
24
+ * - generate reduced/core worker maps
25
+ * - select workers by current runner load
26
+ *
27
+ * Design notes
28
+ * ------------
29
+ * - This is an in-memory registry only.
30
+ * - It stores live manager-side runtime objects, not worker-runtime objects.
31
+ * - It does not perform worker/runner execution itself.
32
+ * - It does not own broker or synchronisation logic; it is purely a shared store
33
+ * plus convenience lookup/selection helpers.
34
+ */
35
+ import { IWorkerEx, IRunnerEx, IRunnerState, IWorkers, IWorkerCore } from './commonTypes';
36
+ import { ISTSLogger } from '@nsshunt/stsutils';
37
+ /**
38
+ * Constructor options for {@link WorkerRegistry}.
39
+ */
40
+ export interface IWorkerRegistryOptions {
41
+ /**
42
+ * Logger used for diagnostics and error reporting.
43
+ */
44
+ logger: ISTSLogger;
45
+ }
46
+ /**
47
+ * Central live registry of workers and runners.
48
+ *
49
+ * This class stores the manager-side live runtime objects and provides lookup,
50
+ * mutation, projection, and simple worker-selection helpers.
51
+ */
52
+ export declare class WorkerRegistry {
53
+ /**
54
+ * Internal live worker map keyed by worker id.
55
+ *
56
+ * Each value is a live manager-side worker instance.
57
+ */
58
+ private readonly workersEx;
59
+ /**
60
+ * Immutable runtime configuration for the registry.
61
+ */
62
+ private readonly options;
63
+ /**
64
+ * Construct a new worker registry.
65
+ *
66
+ * @param options Logger and related registry dependencies.
67
+ */
68
+ constructor(options: IWorkerRegistryOptions);
69
+ /**
70
+ * Add a live worker instance to the registry.
71
+ *
72
+ * Behaviour:
73
+ * - stores the supplied worker under its `id`
74
+ * - replaces any existing worker already stored under the same id
75
+ *
76
+ * Notes:
77
+ * - This method does not validate whether the worker already exists
78
+ * - Callers are responsible for ensuring worker ids are unique
79
+ *
80
+ * @param stsWorkerEx Live worker instance to register.
81
+ */
82
+ AddWorker: (stsWorkerEx: IWorkerEx) => void;
83
+ /**
84
+ * Add a runner to an existing worker in the registry.
85
+ *
86
+ * Behaviour:
87
+ * - resolves the target worker by `workerId`
88
+ * - delegates runner storage to the worker's `AddRunnerEx(...)` method
89
+ *
90
+ * Error handling:
91
+ * - throws if the target worker does not exist
92
+ *
93
+ * @param workerId Id of the worker that should own the runner.
94
+ * @param runnerEx Live runner instance to register.
95
+ * @throws If the target worker does not exist in the registry.
96
+ */
97
+ AddRunner: (workerId: string, runnerEx: IRunnerEx) => void;
98
+ /**
99
+ * Get a live worker instance by id.
100
+ *
101
+ * @param worderId Worker id to resolve.
102
+ * @returns Matching live worker instance, or `undefined` if not found.
103
+ */
104
+ GetWorker: (worderId: string) => IWorkerEx | undefined;
105
+ /**
106
+ * Get a live runner instance by worker id and runner id.
107
+ *
108
+ * Behaviour:
109
+ * - resolves the worker first
110
+ * - asks the worker for the runner by id
111
+ *
112
+ * @param workerId Owning worker id.
113
+ * @param id Runner id.
114
+ * @returns Matching live runner instance, or `null` if not found.
115
+ */
116
+ GetRunnerEx: (workerId: string, id: string) => IRunnerEx | null;
117
+ /**
118
+ * Delete a worker from the live registry.
119
+ *
120
+ * Behaviour:
121
+ * - removes the worker entry if it exists
122
+ * - does nothing if the worker is not present
123
+ *
124
+ * Note:
125
+ * - This does not explicitly terminate the underlying worker
126
+ * - It only removes the manager-side live registry entry
127
+ *
128
+ * @param workerId Worker id to delete.
129
+ */
130
+ DeleteWorker: (workerId: string) => void;
131
+ /**
132
+ * Delete a runner from a worker in the live registry.
133
+ *
134
+ * Behaviour:
135
+ * - resolves the owning worker
136
+ * - resolves the worker's live runner map
137
+ * - deletes the matching runner entry if present
138
+ *
139
+ * Notes:
140
+ * - This operates only on the manager-side live registry
141
+ * - It does not send any message to the worker runtime
142
+ * - It is typically used after a runner has already been archived/retired
143
+ *
144
+ * @param workerId Owning worker id.
145
+ * @param runnerId Runner id to delete.
146
+ */
147
+ DeleteRunner: (workerId: string, runnerId: string) => void;
148
+ /**
149
+ * Build and return the full serialisable workers map.
150
+ *
151
+ * Behaviour:
152
+ * - iterates all live workers
153
+ * - converts each worker to its serialisable `IWorker` representation
154
+ * - returns the full map keyed by worker id
155
+ *
156
+ * Error handling:
157
+ * - logs and re-throws unexpected errors
158
+ *
159
+ * @returns Full serialisable workers map.
160
+ * @throws Re-throws unexpected errors after logging.
161
+ */
162
+ GetWorkersMap: () => IWorkers;
163
+ /**
164
+ * Get the raw live runner map for a specific worker.
165
+ *
166
+ * Behaviour:
167
+ * - resolves the worker by id
168
+ * - returns the worker's internal runner map
169
+ *
170
+ * @param workerId Worker id.
171
+ * @returns Runner map keyed by runner id, or `undefined` if the worker does not exist.
172
+ */
173
+ GetAllRunnersExMap: (workerId: string) => Record<string, IRunnerEx> | undefined;
174
+ /**
175
+ * Get a filtered list of live worker instances.
176
+ *
177
+ * Behaviour:
178
+ * - if `workerIds` is empty, returns all workers
179
+ * - otherwise returns only workers whose ids are present in `workerIds`
180
+ *
181
+ * @param workerIds Worker ids to include. Use `[]` for all workers.
182
+ * @returns Filtered list of live worker instances.
183
+ */
184
+ GetWorkersEx: (workerIds: string[]) => IWorkerEx[];
185
+ /**
186
+ * Get a live worker instance by id.
187
+ *
188
+ * This is functionally equivalent to {@link GetWorker}, but preserves the
189
+ * `Ex` naming convention used elsewhere in the framework.
190
+ *
191
+ * @param workerId Worker id.
192
+ * @returns Matching live worker instance, or `undefined` if not found.
193
+ */
194
+ GetWorkerEx: (workerId: string) => IWorkerEx | undefined;
195
+ /**
196
+ * Build and return the reduced/core workers map.
197
+ *
198
+ * Behaviour:
199
+ * - iterates all live workers
200
+ * - converts each worker to its reduced/core representation
201
+ * - optionally filters included runners by state
202
+ *
203
+ * Runner state filtering:
204
+ * - `undefined` => include all runners
205
+ * - `[]` => include all runners
206
+ * - populated array => include only matching runner states
207
+ *
208
+ * Error handling:
209
+ * - logs and re-throws unexpected errors
210
+ *
211
+ * @param states Optional runner-state filter.
212
+ * @returns Reduced/core workers map keyed by worker id.
213
+ * @throws Re-throws unexpected errors after logging.
214
+ */
215
+ GetWorkersCoreMap: (states?: IRunnerState[]) => Record<string, IWorkerCore>;
216
+ /**
217
+ * Get the worker currently hosting the fewest runners.
218
+ *
219
+ * Selection rule:
220
+ * - returns the worker with the smallest `GetAllRunnersEx().length`
221
+ *
222
+ * Behaviour:
223
+ * - if no workers exist, returns `null`
224
+ * - on error, logs and returns `null`
225
+ *
226
+ * Intended use:
227
+ * - simple load spreading / least-loaded worker selection
228
+ *
229
+ * @returns Least-loaded worker, or `null` if unavailable.
230
+ */
231
+ GetNextAvailableWorker: () => IWorkerEx | null;
232
+ /**
233
+ * Get the worker currently hosting the most runners.
234
+ *
235
+ * Selection rule:
236
+ * - returns the worker with the largest `GetAllRunnersEx().length`
237
+ *
238
+ * Behaviour:
239
+ * - if no workers exist, returns `null`
240
+ * - on error, logs and returns `null`
241
+ *
242
+ * Intended use:
243
+ * - diagnostics
244
+ * - load analysis
245
+ * - busiest-worker selection logic
246
+ *
247
+ * @returns Most-loaded worker, or `null` if unavailable.
248
+ */
249
+ GetBusiestWorker: () => IWorkerEx | null;
250
+ }
251
+ //# sourceMappingURL=workerRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workerRegistry.d.ts","sourceRoot":"","sources":["../src/workerRegistry.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;CACtB;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IACvB;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiC;IAE3D;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IAEjD;;;;OAIG;gBACS,OAAO,EAAE,sBAAsB;IAI3C;;;;;;;;;;;;OAYG;IACH,SAAS,GAAI,aAAa,SAAS,UAEjC;IAEF;;;;;;;;;;;;;OAaG;IACH,SAAS,GAAI,UAAU,MAAM,EAAE,UAAU,SAAS,UAMhD;IAEF;;;;;OAKG;IACH,SAAS,GAAI,UAAU,MAAM,KAAG,SAAS,GAAG,SAAS,CAEnD;IAEF;;;;;;;;;;OAUG;IACH,WAAW,GAAI,UAAU,MAAM,EAAE,IAAI,MAAM,KAAG,SAAS,GAAG,IAAI,CAM5D;IAEF;;;;;;;;;;;;OAYG;IACH,YAAY,GAAI,UAAU,MAAM,KAAG,IAAI,CAIrC;IAEF;;;;;;;;;;;;;;;OAeG;IAC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