@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.mjs
CHANGED
|
@@ -107,124 +107,124 @@ ${parts.join(" ")}`;
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
* Logs an error message with optional additional data.
|
|
111
|
+
*
|
|
112
|
+
* @param msg - The error message to log
|
|
113
|
+
* @param args - Additional data to include in the log entry
|
|
114
|
+
*/
|
|
115
115
|
error(msg, ...args) {
|
|
116
116
|
this.logger.error(msg, ...args);
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
* Logs a warning message with optional additional data.
|
|
120
|
+
*
|
|
121
|
+
* @param msg - The warning message to log
|
|
122
|
+
* @param args - Additional data to include in the log entry
|
|
123
|
+
*/
|
|
124
124
|
warn(msg, ...args) {
|
|
125
125
|
this.logger.warn(msg, ...args);
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
* Logs an informational message with optional additional data.
|
|
129
|
+
*
|
|
130
|
+
* @param msg - The informational message to log
|
|
131
|
+
* @param args - Additional data to include in the log entry
|
|
132
|
+
*/
|
|
133
133
|
info(msg, ...args) {
|
|
134
134
|
this.logger.info(msg, ...args);
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
* Logs an HTTP-related message with optional additional data.
|
|
138
|
+
*
|
|
139
|
+
* @param msg - The HTTP message to log
|
|
140
|
+
* @param args - Additional data to include in the log entry
|
|
141
|
+
*/
|
|
142
142
|
http(msg, ...args) {
|
|
143
143
|
this.logger.http(msg, ...args);
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
* Logs a verbose message with optional additional data.
|
|
147
|
+
*
|
|
148
|
+
* @param msg - The verbose message to log
|
|
149
|
+
* @param args - Additional data to include in the log entry
|
|
150
|
+
*/
|
|
151
151
|
verbose(msg, ...args) {
|
|
152
152
|
this.logger.verbose(msg, ...args);
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
* Logs a debug message with optional additional data.
|
|
156
|
+
*
|
|
157
|
+
* @param msg - The debug message to log
|
|
158
|
+
* @param args - Additional data to include in the log entry
|
|
159
|
+
*/
|
|
160
160
|
debug(msg, ...args) {
|
|
161
161
|
this.logger.debug(msg, ...args);
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
* Logs a silly/trace level message with optional additional data.
|
|
165
|
+
*
|
|
166
|
+
* @param msg - The silly message to log
|
|
167
|
+
* @param args - Additional data to include in the log entry
|
|
168
|
+
*/
|
|
169
169
|
silly(msg, ...args) {
|
|
170
170
|
this.logger.silly(msg, ...args);
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
173
|
+
* Static method to log an error message with a specific prefix.
|
|
174
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
175
|
+
*
|
|
176
|
+
* @param prefix - The logger prefix/label to use
|
|
177
|
+
* @param msg - The error message to log
|
|
178
|
+
* @param args - Additional data to include in the log entry
|
|
179
|
+
*/
|
|
180
180
|
static Error(prefix, msg, ...args) {
|
|
181
181
|
const logger = this.instance(prefix);
|
|
182
182
|
logger.error(msg, ...args);
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
185
|
+
* Static method to log an informational message with a specific prefix.
|
|
186
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
187
|
+
*
|
|
188
|
+
* @param prefix - The logger prefix/label to use
|
|
189
|
+
* @param msg - The informational message to log
|
|
190
|
+
* @param args - Additional data to include in the log entry
|
|
191
|
+
*/
|
|
192
192
|
static Info(prefix, msg, ...args) {
|
|
193
193
|
const logger = this.instance(prefix);
|
|
194
194
|
logger.info(msg, ...args);
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
* Static method to log a warning message with a specific prefix.
|
|
198
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
199
|
+
*
|
|
200
|
+
* @param prefix - The logger prefix/label to use
|
|
201
|
+
* @param msg - The warning message to log
|
|
202
|
+
* @param args - Additional data to include in the log entry
|
|
203
|
+
*/
|
|
204
204
|
static Warn(prefix, msg, ...args) {
|
|
205
205
|
const logger = this.instance(prefix);
|
|
206
206
|
logger.warn(msg, ...args);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
209
|
+
* Static method to log a debug message with a specific prefix.
|
|
210
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
211
|
+
*
|
|
212
|
+
* @param prefix - The logger prefix/label to use
|
|
213
|
+
* @param msg - The debug message to log
|
|
214
|
+
* @param args - Additional data to include in the log entry
|
|
215
|
+
*/
|
|
216
216
|
static Debug(prefix, msg, ...args) {
|
|
217
217
|
const logger = this.instance(prefix);
|
|
218
218
|
logger.debug(msg, ...args);
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
221
|
+
* Static method to log a silly/trace level message with a specific prefix.
|
|
222
|
+
* Creates or retrieves a logger instance for the given prefix.
|
|
223
|
+
*
|
|
224
|
+
* @param prefix - The logger prefix/label to use
|
|
225
|
+
* @param msg - The silly message to log
|
|
226
|
+
* @param args - Additional data to include in the log entry
|
|
227
|
+
*/
|
|
228
228
|
static Silly(prefix, msg, ...args) {
|
|
229
229
|
const logger = this.instance(prefix);
|
|
230
230
|
logger.silly(msg, ...args);
|
|
@@ -246,22 +246,22 @@ var CoordinatedLifecycle = class {
|
|
|
246
246
|
this.phaseOrder.forEach((phase) => this.tasksMap.set(phase, []));
|
|
247
247
|
}
|
|
248
248
|
/**
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
249
|
+
* Adds a lifecycle task to a specific phase.
|
|
250
|
+
*
|
|
251
|
+
* Tasks are executed in phase order during lifecycle operations.
|
|
252
|
+
* Each task has a timeout to prevent hanging operations.
|
|
253
|
+
*
|
|
254
|
+
* @param phase - The lifecycle phase to add the task to
|
|
255
|
+
* @param taskName - Unique name for the task (used for logging and removal)
|
|
256
|
+
* @param task - Async function to execute during the phase
|
|
257
|
+
* @param timeoutMs - Maximum time allowed for task execution in milliseconds
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* lifecycle.addTask(StartupPhase.Services, 'start-database', async () => {
|
|
261
|
+
* await database.connect();
|
|
262
|
+
* }, 10000);
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
265
|
addTask(phase, taskName, task, timeoutMs) {
|
|
266
266
|
if (!this.canAddTask()) return;
|
|
267
267
|
const tasks = this.tasksMap.get(phase);
|
|
@@ -274,12 +274,12 @@ var CoordinatedLifecycle = class {
|
|
|
274
274
|
this.logger.debug(`${chalk.italic("Added")} ${this.getTaskType()} task ${chalk.bold.cyan(taskName)} to phase ${chalk.bold.magenta(this.phaseEnum[phase])}`);
|
|
275
275
|
}
|
|
276
276
|
/**
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
277
|
+
* Removes a lifecycle task from a specific phase.
|
|
278
|
+
*
|
|
279
|
+
* @param phase - The lifecycle phase to remove the task from
|
|
280
|
+
* @param taskName - Name of the task to remove
|
|
281
|
+
* @returns True if the task was found and removed, false otherwise
|
|
282
|
+
*/
|
|
283
283
|
removeTask(phase, taskName) {
|
|
284
284
|
if (!this.canRemoveTask()) return false;
|
|
285
285
|
const tasks = this.tasksMap.get(phase);
|
|
@@ -294,8 +294,8 @@ var CoordinatedLifecycle = class {
|
|
|
294
294
|
return removed;
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
* Run all tasks in a specific phase
|
|
298
|
+
*/
|
|
299
299
|
async runPhase(phase) {
|
|
300
300
|
const tasks = this.tasksMap.get(phase) ?? [];
|
|
301
301
|
if (tasks.length === 0) {
|
|
@@ -315,8 +315,8 @@ var CoordinatedLifecycle = class {
|
|
|
315
315
|
this.emit(`phase:${phase}:complete`);
|
|
316
316
|
}
|
|
317
317
|
/**
|
|
318
|
-
|
|
319
|
-
|
|
318
|
+
* Run a single task with timeout
|
|
319
|
+
*/
|
|
320
320
|
async runTaskWithTimeout(phase, task) {
|
|
321
321
|
this.logger.info(`${chalk.italic("Starting")} task ${chalk.bold.cyan(task.name)} in phase ${chalk.bold.magenta(this.phaseEnum[phase])}`);
|
|
322
322
|
try {
|
|
@@ -335,14 +335,14 @@ var CoordinatedLifecycle = class {
|
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
* Subscribe to lifecycle events
|
|
339
|
+
*/
|
|
340
340
|
on(event, listener) {
|
|
341
341
|
this.events.on(event, listener);
|
|
342
342
|
}
|
|
343
343
|
/**
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
* Unsubscribe from lifecycle events
|
|
345
|
+
*/
|
|
346
346
|
off(event, listener) {
|
|
347
347
|
this.events.off(event, listener);
|
|
348
348
|
}
|
|
@@ -427,41 +427,41 @@ var CoordinatedShutdown = class extends CoordinatedLifecycle {
|
|
|
427
427
|
});
|
|
428
428
|
}
|
|
429
429
|
/**
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
430
|
+
* Adds a task to a specific shutdown phase with timeout.
|
|
431
|
+
*
|
|
432
|
+
* @param phase - The shutdown phase from {@link ShutdownPhase}
|
|
433
|
+
* @param taskName - Unique identifier for the task
|
|
434
|
+
* @param task - Async function to execute
|
|
435
|
+
* @param timeoutMs - Task timeout in milliseconds (default: 5000)
|
|
436
|
+
*/
|
|
437
437
|
addTask(phase, taskName, task, timeoutMs = 5e3) {
|
|
438
438
|
super.addTask(phase, taskName, task, timeoutMs);
|
|
439
439
|
}
|
|
440
440
|
/**
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
441
|
+
* Removes a task from a specific shutdown phase.
|
|
442
|
+
*
|
|
443
|
+
* @param phase - The shutdown phase to remove from
|
|
444
|
+
* @param taskName - Name of the task to remove
|
|
445
|
+
* @returns True if task was found and removed
|
|
446
|
+
*/
|
|
447
447
|
removeTask(phase, taskName) {
|
|
448
448
|
return super.removeTask(phase, taskName);
|
|
449
449
|
}
|
|
450
450
|
/**
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
451
|
+
* Executes the coordinated shutdown sequence.
|
|
452
|
+
*
|
|
453
|
+
* Runs all registered tasks across shutdown phases in reverse order.
|
|
454
|
+
* Tasks within each phase are executed in parallel for faster shutdown.
|
|
455
|
+
* Process exits with the specified code when complete.
|
|
456
|
+
*
|
|
457
|
+
* @param exitCode - Process exit code (default: `0`)
|
|
458
|
+
* @returns Promise that resolves when shutdown is complete
|
|
459
|
+
* @example
|
|
460
|
+
* ```typescript
|
|
461
|
+
* shutdown.addTask(ShutdownPhase.Services, 'database', () => db.disconnect(), 5000);
|
|
462
|
+
* await shutdown.run(0); // Graceful shutdown
|
|
463
|
+
* ```
|
|
464
|
+
*/
|
|
465
465
|
async run(exitCode = 0) {
|
|
466
466
|
if (this.isShuttingDown) {
|
|
467
467
|
this.logger.warn("Shutdown sequence already in progress");
|
|
@@ -488,14 +488,14 @@ var CoordinatedShutdown = class extends CoordinatedLifecycle {
|
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
/**
|
|
491
|
-
|
|
492
|
-
|
|
491
|
+
* Subscribe to shutdown events
|
|
492
|
+
*/
|
|
493
493
|
on(event, listener) {
|
|
494
494
|
super.on(event, listener);
|
|
495
495
|
}
|
|
496
496
|
/**
|
|
497
|
-
|
|
498
|
-
|
|
497
|
+
* Unsubscribe from shutdown events
|
|
498
|
+
*/
|
|
499
499
|
off(event, listener) {
|
|
500
500
|
super.off(event, listener);
|
|
501
501
|
}
|
|
@@ -531,9 +531,9 @@ var HealthCheck = class {
|
|
|
531
531
|
shutdown.addTask(ShutdownPhase.StopServices, "stop-healthcheck-server", async () => await this.stop());
|
|
532
532
|
}
|
|
533
533
|
/**
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
534
|
+
* Starts the health check server.
|
|
535
|
+
* @returns Promise that resolves when the server is listening
|
|
536
|
+
*/
|
|
537
537
|
async init() {
|
|
538
538
|
return new Promise((resolve, reject) => {
|
|
539
539
|
this.server = createServer((req, res) => {
|
|
@@ -555,17 +555,25 @@ var HealthCheck = class {
|
|
|
555
555
|
}
|
|
556
556
|
});
|
|
557
557
|
this.server.on("error", reject);
|
|
558
|
-
this.server.once("listening", () =>
|
|
559
|
-
|
|
560
|
-
this.logger.info(`${chalk.green.bold("\u2713")} Health check server listening on ${chalk.cyan(`http
|
|
558
|
+
this.server.once("listening", () => {
|
|
559
|
+
const address = this.host ?? "localhost";
|
|
560
|
+
this.logger.info(`${chalk.green.bold("\u2713")} Health check server listening on ${chalk.cyan(`http://${address}:${this.port}${this.path}`)}`);
|
|
561
|
+
resolve();
|
|
561
562
|
});
|
|
563
|
+
if (this.host) {
|
|
564
|
+
this.logger.debug(`Binding health check server to ${this.host}`);
|
|
565
|
+
this.server.listen(this.port, this.host);
|
|
566
|
+
} else {
|
|
567
|
+
this.logger.debug("Binding health check server to all interfaces");
|
|
568
|
+
this.server.listen(this.port);
|
|
569
|
+
}
|
|
562
570
|
});
|
|
563
571
|
}
|
|
564
572
|
/**
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
573
|
+
* Stops the health check server.
|
|
574
|
+
*
|
|
575
|
+
* @returns Promise that resolves when the server is closed
|
|
576
|
+
*/
|
|
569
577
|
stop() {
|
|
570
578
|
if (this.server !== void 0) {
|
|
571
579
|
const server = this.server;
|
|
@@ -591,6 +599,10 @@ _ts_decorate2([
|
|
|
591
599
|
}),
|
|
592
600
|
_ts_metadata2("design:type", String)
|
|
593
601
|
], HealthCheck.prototype, "path", void 0);
|
|
602
|
+
_ts_decorate2([
|
|
603
|
+
Envapt("HEALTH_CHECK_HOST"),
|
|
604
|
+
_ts_metadata2("design:type", Object)
|
|
605
|
+
], HealthCheck.prototype, "host", void 0);
|
|
594
606
|
var CooldownManager = class {
|
|
595
607
|
static {
|
|
596
608
|
__name(this, "CooldownManager");
|
|
@@ -600,32 +612,32 @@ var CooldownManager = class {
|
|
|
600
612
|
msg;
|
|
601
613
|
map = /* @__PURE__ */ new Map();
|
|
602
614
|
/**
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
615
|
+
* Creates a new CooldownManager instance.
|
|
616
|
+
*
|
|
617
|
+
* @param opts - Configuration options for the cooldown behavior
|
|
618
|
+
*/
|
|
607
619
|
constructor(opts = {}) {
|
|
608
620
|
this.window = opts.cooldown ?? 1e3;
|
|
609
621
|
this.Err = opts.err ?? Error;
|
|
610
622
|
this.msg = opts.message ?? "Cooldown active";
|
|
611
623
|
}
|
|
612
624
|
/**
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
625
|
+
* Records usage timestamp for a key without any cooldown checks.
|
|
626
|
+
*
|
|
627
|
+
* @param key - The unique identifier for the cooldown entry
|
|
628
|
+
*/
|
|
617
629
|
set(key) {
|
|
618
630
|
this.map.set(key, Date.now());
|
|
619
631
|
}
|
|
620
632
|
/**
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
633
|
+
* Verifies cooldown status for a key and updates timestamp if not active.
|
|
634
|
+
*
|
|
635
|
+
* If the cooldown is still active, throws the configured error.
|
|
636
|
+
* If not active, updates the timestamp and returns successfully.
|
|
637
|
+
*
|
|
638
|
+
* @param key - The unique identifier to check cooldown for
|
|
639
|
+
* @throws An {@link Err} When the cooldown is still active for the given key
|
|
640
|
+
*/
|
|
629
641
|
check(key) {
|
|
630
642
|
const now = Date.now();
|
|
631
643
|
const last = this.map.get(key);
|
|
@@ -639,20 +651,20 @@ var CooldownManager = class {
|
|
|
639
651
|
this.map.set(key, now);
|
|
640
652
|
}
|
|
641
653
|
/**
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
654
|
+
* Checks if a key is currently cooling down without updating timestamp.
|
|
655
|
+
*
|
|
656
|
+
* @param key - The unique identifier to check
|
|
657
|
+
* @returns True if the key is still cooling down, false otherwise
|
|
658
|
+
*/
|
|
647
659
|
isActive(key) {
|
|
648
660
|
const last = this.map.get(key);
|
|
649
661
|
return last !== void 0 && Date.now() - last < this.window;
|
|
650
662
|
}
|
|
651
663
|
/**
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
664
|
+
* Removes a key from the cooldown map.
|
|
665
|
+
*
|
|
666
|
+
* @param key - The unique identifier to remove (useful for manual resets)
|
|
667
|
+
*/
|
|
656
668
|
clear(key) {
|
|
657
669
|
this.map.delete(key);
|
|
658
670
|
}
|
|
@@ -686,13 +698,13 @@ var CoordinatedStartup = class extends CoordinatedLifecycle {
|
|
|
686
698
|
super("CoordinatedStartup", PHASE_ORDER2, StartupPhase);
|
|
687
699
|
}
|
|
688
700
|
/**
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
701
|
+
* Adds a task to a specific startup phase with timeout.
|
|
702
|
+
*
|
|
703
|
+
* @param phase - The startup phase from {@link StartupPhase}
|
|
704
|
+
* @param taskName - Unique identifier for the task
|
|
705
|
+
* @param task - Async function to execute
|
|
706
|
+
* @param timeoutMs - Task timeout in milliseconds (default: 10000)
|
|
707
|
+
*/
|
|
696
708
|
addTask(phase, taskName, task, timeoutMs = 1e4) {
|
|
697
709
|
super.addTask(phase, taskName, task, timeoutMs);
|
|
698
710
|
}
|
|
@@ -732,21 +744,21 @@ var CoordinatedStartup = class extends CoordinatedLifecycle {
|
|
|
732
744
|
return results;
|
|
733
745
|
}
|
|
734
746
|
/**
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
747
|
+
* Executes the coordinated startup sequence.
|
|
748
|
+
*
|
|
749
|
+
* Runs all registered tasks across startup phases in the correct order.
|
|
750
|
+
* Each phase completes before the next phase begins. Tasks within a phase
|
|
751
|
+
* are executed sequentially to maintain predictable initialization.
|
|
752
|
+
*
|
|
753
|
+
* @returns Promise that resolves when startup is complete
|
|
754
|
+
* @throws An {@link Error} If startup fails or is called multiple times
|
|
755
|
+
* @example
|
|
756
|
+
* ```typescript
|
|
757
|
+
* const startup = new CoordinatedStartup();
|
|
758
|
+
* startup.addTask(StartupPhase.Services, 'database', () => db.connect(), 10000);
|
|
759
|
+
* await startup.run();
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
750
762
|
async run() {
|
|
751
763
|
if (this.hasStarted) {
|
|
752
764
|
this.logger.warn("Startup sequence has already completed");
|
|
@@ -773,26 +785,26 @@ var CoordinatedStartup = class extends CoordinatedLifecycle {
|
|
|
773
785
|
}
|
|
774
786
|
}
|
|
775
787
|
/**
|
|
776
|
-
|
|
777
|
-
|
|
788
|
+
* Subscribe to startup events
|
|
789
|
+
*/
|
|
778
790
|
on(event, listener) {
|
|
779
791
|
super.on(event, listener);
|
|
780
792
|
}
|
|
781
793
|
/**
|
|
782
|
-
|
|
783
|
-
|
|
794
|
+
* Unsubscribe from startup events
|
|
795
|
+
*/
|
|
784
796
|
off(event, listener) {
|
|
785
797
|
super.off(event, listener);
|
|
786
798
|
}
|
|
787
799
|
/**
|
|
788
|
-
|
|
789
|
-
|
|
800
|
+
* Check if startup has completed
|
|
801
|
+
*/
|
|
790
802
|
get isReady() {
|
|
791
803
|
return this.hasStarted;
|
|
792
804
|
}
|
|
793
805
|
/**
|
|
794
|
-
|
|
795
|
-
|
|
806
|
+
* Check if startup is currently running
|
|
807
|
+
*/
|
|
796
808
|
get isRunning() {
|
|
797
809
|
return this.isStartingUp;
|
|
798
810
|
}
|