@seedcord/services 0.2.1 → 0.3.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/index.cjs +208 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -4
- package/dist/index.d.ts +47 -4
- package/dist/index.mjs +208 -196
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -113,124 +113,124 @@ ${parts.join(" ")}`;
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
* Logs an error message with optional additional data.
|
|
117
|
+
*
|
|
118
|
+
* @param msg - The error message to log
|
|
119
|
+
* @param args - Additional data to include in the log entry
|
|
120
|
+
*/
|
|
121
121
|
error(msg, ...args) {
|
|
122
122
|
this.logger.error(msg, ...args);
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
* Logs a warning message with optional additional data.
|
|
126
|
+
*
|
|
127
|
+
* @param msg - The warning message to log
|
|
128
|
+
* @param args - Additional data to include in the log entry
|
|
129
|
+
*/
|
|
130
130
|
warn(msg, ...args) {
|
|
131
131
|
this.logger.warn(msg, ...args);
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
* Logs an informational message with optional additional data.
|
|
135
|
+
*
|
|
136
|
+
* @param msg - The informational message to log
|
|
137
|
+
* @param args - Additional data to include in the log entry
|
|
138
|
+
*/
|
|
139
139
|
info(msg, ...args) {
|
|
140
140
|
this.logger.info(msg, ...args);
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
* Logs an HTTP-related message with optional additional data.
|
|
144
|
+
*
|
|
145
|
+
* @param msg - The HTTP message to log
|
|
146
|
+
* @param args - Additional data to include in the log entry
|
|
147
|
+
*/
|
|
148
148
|
http(msg, ...args) {
|
|
149
149
|
this.logger.http(msg, ...args);
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
* Logs a verbose message with optional additional data.
|
|
153
|
+
*
|
|
154
|
+
* @param msg - The verbose message to log
|
|
155
|
+
* @param args - Additional data to include in the log entry
|
|
156
|
+
*/
|
|
157
157
|
verbose(msg, ...args) {
|
|
158
158
|
this.logger.verbose(msg, ...args);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
* Logs a debug message with optional additional data.
|
|
162
|
+
*
|
|
163
|
+
* @param msg - The debug message to log
|
|
164
|
+
* @param args - Additional data to include in the log entry
|
|
165
|
+
*/
|
|
166
166
|
debug(msg, ...args) {
|
|
167
167
|
this.logger.debug(msg, ...args);
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
* Logs a silly/trace level message with optional additional data.
|
|
171
|
+
*
|
|
172
|
+
* @param msg - The silly message to log
|
|
173
|
+
* @param args - Additional data to include in the log entry
|
|
174
|
+
*/
|
|
175
175
|
silly(msg, ...args) {
|
|
176
176
|
this.logger.silly(msg, ...args);
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
* Static method to log an error message with a specific prefix.
|
|
180
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
181
|
+
*
|
|
182
|
+
* @param prefix - The logger prefix/label to use
|
|
183
|
+
* @param msg - The error message to log
|
|
184
|
+
* @param args - Additional data to include in the log entry
|
|
185
|
+
*/
|
|
186
186
|
static Error(prefix, msg, ...args) {
|
|
187
187
|
const logger = this.instance(prefix);
|
|
188
188
|
logger.error(msg, ...args);
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
* Static method to log an informational message with a specific prefix.
|
|
192
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
193
|
+
*
|
|
194
|
+
* @param prefix - The logger prefix/label to use
|
|
195
|
+
* @param msg - The informational message to log
|
|
196
|
+
* @param args - Additional data to include in the log entry
|
|
197
|
+
*/
|
|
198
198
|
static Info(prefix, msg, ...args) {
|
|
199
199
|
const logger = this.instance(prefix);
|
|
200
200
|
logger.info(msg, ...args);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
203
|
+
* Static method to log a warning message with a specific prefix.
|
|
204
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
205
|
+
*
|
|
206
|
+
* @param prefix - The logger prefix/label to use
|
|
207
|
+
* @param msg - The warning message to log
|
|
208
|
+
* @param args - Additional data to include in the log entry
|
|
209
|
+
*/
|
|
210
210
|
static Warn(prefix, msg, ...args) {
|
|
211
211
|
const logger = this.instance(prefix);
|
|
212
212
|
logger.warn(msg, ...args);
|
|
213
213
|
}
|
|
214
214
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
215
|
+
* Static method to log a debug message with a specific prefix.
|
|
216
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
217
|
+
*
|
|
218
|
+
* @param prefix - The logger prefix/label to use
|
|
219
|
+
* @param msg - The debug message to log
|
|
220
|
+
* @param args - Additional data to include in the log entry
|
|
221
|
+
*/
|
|
222
222
|
static Debug(prefix, msg, ...args) {
|
|
223
223
|
const logger = this.instance(prefix);
|
|
224
224
|
logger.debug(msg, ...args);
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
227
|
+
* Static method to log a silly/trace level message with a specific prefix.
|
|
228
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
229
|
+
*
|
|
230
|
+
* @param prefix - The logger prefix/label to use
|
|
231
|
+
* @param msg - The silly message to log
|
|
232
|
+
* @param args - Additional data to include in the log entry
|
|
233
|
+
*/
|
|
234
234
|
static Silly(prefix, msg, ...args) {
|
|
235
235
|
const logger = this.instance(prefix);
|
|
236
236
|
logger.silly(msg, ...args);
|
|
@@ -252,22 +252,22 @@ var CoordinatedLifecycle = class {
|
|
|
252
252
|
this.phaseOrder.forEach((phase) => this.tasksMap.set(phase, []));
|
|
253
253
|
}
|
|
254
254
|
/**
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
255
|
+
* Adds a lifecycle task to a specific phase.
|
|
256
|
+
*
|
|
257
|
+
* Tasks are executed in phase order during lifecycle operations.
|
|
258
|
+
* Each task has a timeout to prevent hanging operations.
|
|
259
|
+
*
|
|
260
|
+
* @param phase - The lifecycle phase to add the task to
|
|
261
|
+
* @param taskName - Unique name for the task (used for logging and removal)
|
|
262
|
+
* @param task - Async function to execute during the phase
|
|
263
|
+
* @param timeoutMs - Maximum time allowed for task execution in milliseconds
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* lifecycle.addTask(StartupPhase.Services, 'start-database', async () => {
|
|
267
|
+
* await database.connect();
|
|
268
|
+
* }, 10000);
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
271
|
addTask(phase, taskName, task, timeoutMs) {
|
|
272
272
|
if (!this.canAddTask()) return;
|
|
273
273
|
const tasks = this.tasksMap.get(phase);
|
|
@@ -280,12 +280,12 @@ var CoordinatedLifecycle = class {
|
|
|
280
280
|
this.logger.debug(`${chalk__default.default.italic("Added")} ${this.getTaskType()} task ${chalk__default.default.bold.cyan(taskName)} to phase ${chalk__default.default.bold.magenta(this.phaseEnum[phase])}`);
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
283
|
+
* Removes a lifecycle task from a specific phase.
|
|
284
|
+
*
|
|
285
|
+
* @param phase - The lifecycle phase to remove the task from
|
|
286
|
+
* @param taskName - Name of the task to remove
|
|
287
|
+
* @returns True if the task was found and removed, false otherwise
|
|
288
|
+
*/
|
|
289
289
|
removeTask(phase, taskName) {
|
|
290
290
|
if (!this.canRemoveTask()) return false;
|
|
291
291
|
const tasks = this.tasksMap.get(phase);
|
|
@@ -300,8 +300,8 @@ var CoordinatedLifecycle = class {
|
|
|
300
300
|
return removed;
|
|
301
301
|
}
|
|
302
302
|
/**
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
* Run all tasks in a specific phase
|
|
304
|
+
*/
|
|
305
305
|
async runPhase(phase) {
|
|
306
306
|
const tasks = this.tasksMap.get(phase) ?? [];
|
|
307
307
|
if (tasks.length === 0) {
|
|
@@ -321,8 +321,8 @@ var CoordinatedLifecycle = class {
|
|
|
321
321
|
this.emit(`phase:${phase}:complete`);
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
324
|
-
|
|
325
|
-
|
|
324
|
+
* Run a single task with timeout
|
|
325
|
+
*/
|
|
326
326
|
async runTaskWithTimeout(phase, task) {
|
|
327
327
|
this.logger.info(`${chalk__default.default.italic("Starting")} task ${chalk__default.default.bold.cyan(task.name)} in phase ${chalk__default.default.bold.magenta(this.phaseEnum[phase])}`);
|
|
328
328
|
try {
|
|
@@ -341,14 +341,14 @@ var CoordinatedLifecycle = class {
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
/**
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
* Subscribe to lifecycle events
|
|
345
|
+
*/
|
|
346
346
|
on(event, listener) {
|
|
347
347
|
this.events.on(event, listener);
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
|
-
|
|
351
|
-
|
|
350
|
+
* Unsubscribe from lifecycle events
|
|
351
|
+
*/
|
|
352
352
|
off(event, listener) {
|
|
353
353
|
this.events.off(event, listener);
|
|
354
354
|
}
|
|
@@ -433,41 +433,41 @@ var CoordinatedShutdown = class extends CoordinatedLifecycle {
|
|
|
433
433
|
});
|
|
434
434
|
}
|
|
435
435
|
/**
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
436
|
+
* Adds a task to a specific shutdown phase with timeout.
|
|
437
|
+
*
|
|
438
|
+
* @param phase - The shutdown phase from {@link ShutdownPhase}
|
|
439
|
+
* @param taskName - Unique identifier for the task
|
|
440
|
+
* @param task - Async function to execute
|
|
441
|
+
* @param timeoutMs - Task timeout in milliseconds (default: 5000)
|
|
442
|
+
*/
|
|
443
443
|
addTask(phase, taskName, task, timeoutMs = 5e3) {
|
|
444
444
|
super.addTask(phase, taskName, task, timeoutMs);
|
|
445
445
|
}
|
|
446
446
|
/**
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
447
|
+
* Removes a task from a specific shutdown phase.
|
|
448
|
+
*
|
|
449
|
+
* @param phase - The shutdown phase to remove from
|
|
450
|
+
* @param taskName - Name of the task to remove
|
|
451
|
+
* @returns True if task was found and removed
|
|
452
|
+
*/
|
|
453
453
|
removeTask(phase, taskName) {
|
|
454
454
|
return super.removeTask(phase, taskName);
|
|
455
455
|
}
|
|
456
456
|
/**
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
457
|
+
* Executes the coordinated shutdown sequence.
|
|
458
|
+
*
|
|
459
|
+
* Runs all registered tasks across shutdown phases in reverse order.
|
|
460
|
+
* Tasks within each phase are executed in parallel for faster shutdown.
|
|
461
|
+
* Process exits with the specified code when complete.
|
|
462
|
+
*
|
|
463
|
+
* @param exitCode - Process exit code (default: `0`)
|
|
464
|
+
* @returns Promise that resolves when shutdown is complete
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* shutdown.addTask(ShutdownPhase.Services, 'database', () => db.disconnect(), 5000);
|
|
468
|
+
* await shutdown.run(0); // Graceful shutdown
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
471
|
async run(exitCode = 0) {
|
|
472
472
|
if (this.isShuttingDown) {
|
|
473
473
|
this.logger.warn("Shutdown sequence already in progress");
|
|
@@ -494,14 +494,14 @@ var CoordinatedShutdown = class extends CoordinatedLifecycle {
|
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
/**
|
|
497
|
-
|
|
498
|
-
|
|
497
|
+
* Subscribe to shutdown events
|
|
498
|
+
*/
|
|
499
499
|
on(event, listener) {
|
|
500
500
|
super.on(event, listener);
|
|
501
501
|
}
|
|
502
502
|
/**
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
* Unsubscribe from shutdown events
|
|
504
|
+
*/
|
|
505
505
|
off(event, listener) {
|
|
506
506
|
super.off(event, listener);
|
|
507
507
|
}
|
|
@@ -537,9 +537,9 @@ var HealthCheck = class {
|
|
|
537
537
|
shutdown.addTask(ShutdownPhase.StopServices, "stop-healthcheck-server", async () => await this.stop());
|
|
538
538
|
}
|
|
539
539
|
/**
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
540
|
+
* Starts the health check server.
|
|
541
|
+
* @returns Promise that resolves when the server is listening
|
|
542
|
+
*/
|
|
543
543
|
async init() {
|
|
544
544
|
return new Promise((resolve, reject) => {
|
|
545
545
|
this.server = http.createServer((req, res) => {
|
|
@@ -561,17 +561,25 @@ var HealthCheck = class {
|
|
|
561
561
|
}
|
|
562
562
|
});
|
|
563
563
|
this.server.on("error", reject);
|
|
564
|
-
this.server.once("listening", () =>
|
|
565
|
-
|
|
566
|
-
this.logger.info(`${chalk__default.default.green.bold("\u2713")} Health check server listening on ${chalk__default.default.cyan(`http
|
|
564
|
+
this.server.once("listening", () => {
|
|
565
|
+
const address = this.host ?? "localhost";
|
|
566
|
+
this.logger.info(`${chalk__default.default.green.bold("\u2713")} Health check server listening on ${chalk__default.default.cyan(`http://${address}:${this.port}${this.path}`)}`);
|
|
567
|
+
resolve();
|
|
567
568
|
});
|
|
569
|
+
if (this.host) {
|
|
570
|
+
this.logger.debug(`Binding health check server to ${this.host}`);
|
|
571
|
+
this.server.listen(this.port, this.host);
|
|
572
|
+
} else {
|
|
573
|
+
this.logger.debug("Binding health check server to all interfaces");
|
|
574
|
+
this.server.listen(this.port);
|
|
575
|
+
}
|
|
568
576
|
});
|
|
569
577
|
}
|
|
570
578
|
/**
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
579
|
+
* Stops the health check server.
|
|
580
|
+
*
|
|
581
|
+
* @returns Promise that resolves when the server is closed
|
|
582
|
+
*/
|
|
575
583
|
stop() {
|
|
576
584
|
if (this.server !== void 0) {
|
|
577
585
|
const server = this.server;
|
|
@@ -597,6 +605,10 @@ _ts_decorate2([
|
|
|
597
605
|
}),
|
|
598
606
|
_ts_metadata2("design:type", String)
|
|
599
607
|
], HealthCheck.prototype, "path", void 0);
|
|
608
|
+
_ts_decorate2([
|
|
609
|
+
envapt.Envapt("HEALTH_CHECK_HOST"),
|
|
610
|
+
_ts_metadata2("design:type", Object)
|
|
611
|
+
], HealthCheck.prototype, "host", void 0);
|
|
600
612
|
var CooldownManager = class {
|
|
601
613
|
static {
|
|
602
614
|
__name(this, "CooldownManager");
|
|
@@ -606,32 +618,32 @@ var CooldownManager = class {
|
|
|
606
618
|
msg;
|
|
607
619
|
map = /* @__PURE__ */ new Map();
|
|
608
620
|
/**
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
621
|
+
* Creates a new CooldownManager instance.
|
|
622
|
+
*
|
|
623
|
+
* @param opts - Configuration options for the cooldown behavior
|
|
624
|
+
*/
|
|
613
625
|
constructor(opts = {}) {
|
|
614
626
|
this.window = opts.cooldown ?? 1e3;
|
|
615
627
|
this.Err = opts.err ?? Error;
|
|
616
628
|
this.msg = opts.message ?? "Cooldown active";
|
|
617
629
|
}
|
|
618
630
|
/**
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
631
|
+
* Records usage timestamp for a key without any cooldown checks.
|
|
632
|
+
*
|
|
633
|
+
* @param key - The unique identifier for the cooldown entry
|
|
634
|
+
*/
|
|
623
635
|
set(key) {
|
|
624
636
|
this.map.set(key, Date.now());
|
|
625
637
|
}
|
|
626
638
|
/**
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
639
|
+
* Verifies cooldown status for a key and updates timestamp if not active.
|
|
640
|
+
*
|
|
641
|
+
* If the cooldown is still active, throws the configured error.
|
|
642
|
+
* If not active, updates the timestamp and returns successfully.
|
|
643
|
+
*
|
|
644
|
+
* @param key - The unique identifier to check cooldown for
|
|
645
|
+
* @throws An {@link Err} When the cooldown is still active for the given key
|
|
646
|
+
*/
|
|
635
647
|
check(key) {
|
|
636
648
|
const now = Date.now();
|
|
637
649
|
const last = this.map.get(key);
|
|
@@ -645,20 +657,20 @@ var CooldownManager = class {
|
|
|
645
657
|
this.map.set(key, now);
|
|
646
658
|
}
|
|
647
659
|
/**
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
660
|
+
* Checks if a key is currently cooling down without updating timestamp.
|
|
661
|
+
*
|
|
662
|
+
* @param key - The unique identifier to check
|
|
663
|
+
* @returns True if the key is still cooling down, false otherwise
|
|
664
|
+
*/
|
|
653
665
|
isActive(key) {
|
|
654
666
|
const last = this.map.get(key);
|
|
655
667
|
return last !== void 0 && Date.now() - last < this.window;
|
|
656
668
|
}
|
|
657
669
|
/**
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
670
|
+
* Removes a key from the cooldown map.
|
|
671
|
+
*
|
|
672
|
+
* @param key - The unique identifier to remove (useful for manual resets)
|
|
673
|
+
*/
|
|
662
674
|
clear(key) {
|
|
663
675
|
this.map.delete(key);
|
|
664
676
|
}
|
|
@@ -692,13 +704,13 @@ var CoordinatedStartup = class extends CoordinatedLifecycle {
|
|
|
692
704
|
super("CoordinatedStartup", PHASE_ORDER2, StartupPhase);
|
|
693
705
|
}
|
|
694
706
|
/**
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
707
|
+
* Adds a task to a specific startup phase with timeout.
|
|
708
|
+
*
|
|
709
|
+
* @param phase - The startup phase from {@link StartupPhase}
|
|
710
|
+
* @param taskName - Unique identifier for the task
|
|
711
|
+
* @param task - Async function to execute
|
|
712
|
+
* @param timeoutMs - Task timeout in milliseconds (default: 10000)
|
|
713
|
+
*/
|
|
702
714
|
addTask(phase, taskName, task, timeoutMs = 1e4) {
|
|
703
715
|
super.addTask(phase, taskName, task, timeoutMs);
|
|
704
716
|
}
|
|
@@ -738,21 +750,21 @@ var CoordinatedStartup = class extends CoordinatedLifecycle {
|
|
|
738
750
|
return results;
|
|
739
751
|
}
|
|
740
752
|
/**
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
753
|
+
* Executes the coordinated startup sequence.
|
|
754
|
+
*
|
|
755
|
+
* Runs all registered tasks across startup phases in the correct order.
|
|
756
|
+
* Each phase completes before the next phase begins. Tasks within a phase
|
|
757
|
+
* are executed sequentially to maintain predictable initialization.
|
|
758
|
+
*
|
|
759
|
+
* @returns Promise that resolves when startup is complete
|
|
760
|
+
* @throws An {@link Error} If startup fails or is called multiple times
|
|
761
|
+
* @example
|
|
762
|
+
* ```typescript
|
|
763
|
+
* const startup = new CoordinatedStartup();
|
|
764
|
+
* startup.addTask(StartupPhase.Services, 'database', () => db.connect(), 10000);
|
|
765
|
+
* await startup.run();
|
|
766
|
+
* ```
|
|
767
|
+
*/
|
|
756
768
|
async run() {
|
|
757
769
|
if (this.hasStarted) {
|
|
758
770
|
this.logger.warn("Startup sequence has already completed");
|
|
@@ -779,26 +791,26 @@ var CoordinatedStartup = class extends CoordinatedLifecycle {
|
|
|
779
791
|
}
|
|
780
792
|
}
|
|
781
793
|
/**
|
|
782
|
-
|
|
783
|
-
|
|
794
|
+
* Subscribe to startup events
|
|
795
|
+
*/
|
|
784
796
|
on(event, listener) {
|
|
785
797
|
super.on(event, listener);
|
|
786
798
|
}
|
|
787
799
|
/**
|
|
788
|
-
|
|
789
|
-
|
|
800
|
+
* Unsubscribe from startup events
|
|
801
|
+
*/
|
|
790
802
|
off(event, listener) {
|
|
791
803
|
super.off(event, listener);
|
|
792
804
|
}
|
|
793
805
|
/**
|
|
794
|
-
|
|
795
|
-
|
|
806
|
+
* Check if startup has completed
|
|
807
|
+
*/
|
|
796
808
|
get isReady() {
|
|
797
809
|
return this.hasStarted;
|
|
798
810
|
}
|
|
799
811
|
/**
|
|
800
|
-
|
|
801
|
-
|
|
812
|
+
* Check if startup is currently running
|
|
813
|
+
*/
|
|
802
814
|
get isRunning() {
|
|
803
815
|
return this.isStartingUp;
|
|
804
816
|
}
|