Minor cleanup based on feedback.

Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
Eric Peterson
2024-10-01 14:10:16 +02:00
parent 8bfe9f0f61
commit 1aaaf70337
3 changed files with 10 additions and 7 deletions
@@ -408,19 +408,18 @@ export class BackendInitializer {
}
// Get all plugins.
const pluginMap = new Map<string, boolean>();
const allPlugins = new Set<string>();
for (const feature of this.#registrations) {
for (const r of feature.getRegistrations()) {
if (r.type === 'plugin') {
pluginMap.set(r.pluginId, true);
allPlugins.add(r.pluginId);
}
}
}
const allPluginIds = Array.from(pluginMap.keys());
// Iterate through all plugins and run their shutdown hooks.
await Promise.allSettled(
allPluginIds.map(async pluginId => {
[...allPlugins].map(async pluginId => {
const lifecycleService = await this.#getPluginLifecycleImpl(pluginId);
await lifecycleService.shutdown();
}),
@@ -466,7 +465,11 @@ export class BackendInitializer {
);
const service = lifecycleService as any;
if (service && typeof service.startup === 'function') {
if (
service &&
typeof service.startup === 'function' &&
typeof service.shutdown === 'function'
) {
return service;
}
@@ -94,7 +94,7 @@ export class DatabaseManagerImpl {
*/
async shutdown(deps: { logger: LoggerService }): Promise<void> {
const pluginIds = Array.from(this.databaseCache.keys());
await Promise.all(
await Promise.allSettled(
pluginIds.map(async pluginId => {
const connection = await this.databaseCache.get(pluginId);
if (connection) {
@@ -111,7 +111,7 @@ export class BackendPluginLifecycleImpl implements LifecycleService {
await hook();
logger.debug(`Plugin shutdown hook succeeded`);
} catch (error) {
logger.error(`Plugin shutdown hook failed, ${error}`);
logger.error('Plugin shutdown hook failed', error);
}
}),
);