refactor: share research domain and simplify application workflows
This commit is contained in:
parent
805a9f8fd4
commit
8c39ccf7ea
58 changed files with 3805 additions and 3081 deletions
|
|
@ -114,7 +114,7 @@ export class ServiceContainerBuilder {
|
|||
mongodb: {
|
||||
...(config.mongodb || {
|
||||
enabled: this.options.enableMongoDB ?? true,
|
||||
uri: '',
|
||||
uri: 'mongodb://localhost:27017',
|
||||
database: '',
|
||||
}),
|
||||
enabled: this.options.enableMongoDB !== false && (config.mongodb?.enabled ?? true),
|
||||
|
|
|
|||
|
|
@ -31,14 +31,18 @@ export class ServiceLifecycleManager {
|
|||
try {
|
||||
const work = this.services.map(async ({ name, key }) => {
|
||||
const service = container.cradle[key] as ServiceWithLifecycle | null;
|
||||
if (!service) {return Promise.resolve();}
|
||||
if (!service) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const entry = { name, service, settled: false };
|
||||
started.push(entry);
|
||||
// A timeout cannot cancel connect(). Keep ownership until it settles,
|
||||
// including resources allocated by an initializer that later rejects.
|
||||
const initialization = this.initializeService(name, service).finally(async () => {
|
||||
entry.settled = true;
|
||||
if (failed) {await this.cleanupOnce(name, service);}
|
||||
if (failed) {
|
||||
await this.cleanupOnce(name, service);
|
||||
}
|
||||
});
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
const expired = new Promise<never>((_, reject) => {
|
||||
|
|
@ -65,7 +69,9 @@ export class ServiceLifecycleManager {
|
|||
);
|
||||
throw error;
|
||||
} finally {
|
||||
for (const clear of cancelTimers) {clear();}
|
||||
for (const clear of cancelTimers) {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +92,9 @@ export class ServiceLifecycleManager {
|
|||
for (const { name, key } of [...this.services].reverse()) {
|
||||
try {
|
||||
const service = container.cradle[key] as ServiceWithLifecycle | null;
|
||||
if (service) {await this.cleanupOnce(name, service);}
|
||||
if (service) {
|
||||
await this.cleanupOnce(name, service);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`Error resolving ${name} during shutdown:`, error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue