chore: Rename options, add additional logging
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -20,19 +20,23 @@ import {
|
||||
loggerToWinstonLogger,
|
||||
pluginMetadataServiceRef,
|
||||
rootLoggerServiceRef,
|
||||
ShutdownHookOptions,
|
||||
BackendLifecycleShutdownHook,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
class BackendLifecycleImpl {
|
||||
constructor(private readonly logger: Logger) {}
|
||||
#shutdownTasks: Array<ShutdownHookOptions & { pluginId: string }> = [];
|
||||
#shutdownTasks: Array<BackendLifecycleShutdownHook & { pluginId: string }> =
|
||||
[];
|
||||
|
||||
addShutdownHook(options: ShutdownHookOptions & { pluginId: string }): void {
|
||||
addShutdownHook(
|
||||
options: BackendLifecycleShutdownHook & { pluginId: string },
|
||||
): void {
|
||||
this.#shutdownTasks.push(options);
|
||||
}
|
||||
|
||||
async shutdown(): Promise<void> {
|
||||
this.logger.info(`Running ${this.#shutdownTasks.length} shutdown tasks...`);
|
||||
await Promise.all(
|
||||
this.#shutdownTasks.map(hook =>
|
||||
hook
|
||||
@@ -57,7 +61,7 @@ class PluginScopedLifecycleImpl implements BackendLifecycle {
|
||||
private readonly lifecycle: BackendLifecycleImpl,
|
||||
private readonly pluginId: string,
|
||||
) {}
|
||||
addShutdownHook(options: ShutdownHookOptions): void {
|
||||
addShutdownHook(options: BackendLifecycleShutdownHook): void {
|
||||
this.lifecycle.addShutdownHook({ ...options, pluginId: this.pluginId });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ export { pluginMetadataServiceRef } from './pluginMetadataServiceRef';
|
||||
export { lifecycleServiceRef } from './lifecycleServiceRef';
|
||||
export type {
|
||||
BackendLifecycle,
|
||||
ShutdownHookOptions,
|
||||
BackendLifecycleShutdownHook,
|
||||
} from './lifecycleServiceRef';
|
||||
export type { PluginMetadata } from './pluginMetadataServiceRef';
|
||||
|
||||
@@ -19,7 +19,7 @@ import { createServiceRef } from '../system/types';
|
||||
/**
|
||||
* @public
|
||||
**/
|
||||
export type ShutdownHookOptions = {
|
||||
export type BackendLifecycleShutdownHook = {
|
||||
fn: () => Promise<void>;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ export interface BackendLifecycle {
|
||||
/**
|
||||
* Register a function to be called when the backend is shutting down.
|
||||
*/
|
||||
addShutdownHook(options: ShutdownHookOptions): void;
|
||||
addShutdownHook(options: BackendLifecycleShutdownHook): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user