backend-app-api,backend-test-api: hook up shutdown hook to stop method
Co-authored-by: Johan Haals <johan.haals@gmail.com> Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -26,6 +26,8 @@ export interface Backend {
|
||||
add(feature: BackendFeature): void;
|
||||
// (undocumented)
|
||||
start(): Promise<void>;
|
||||
// (undocumented)
|
||||
stop(): Promise<void>;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
import {
|
||||
BackendFeature,
|
||||
ExtensionPoint,
|
||||
lifecycleServiceRef,
|
||||
ServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { BackendLifecycleImpl } from '../services/implementations/lifecycleService';
|
||||
import {
|
||||
BackendRegisterInit,
|
||||
ServiceHolder,
|
||||
@@ -165,4 +167,24 @@ export class BackendInitializer {
|
||||
|
||||
return orderedRegisterInits;
|
||||
}
|
||||
|
||||
async stop(): Promise<void> {
|
||||
if (!this.#started) {
|
||||
throw new Error('Backend has not started');
|
||||
}
|
||||
this.#started = false;
|
||||
|
||||
const lifecycleService = await this.#serviceHolder.get(
|
||||
lifecycleServiceRef,
|
||||
'root',
|
||||
);
|
||||
|
||||
// TODO(Rugvip): :D
|
||||
const lifecycle = (lifecycleService as any)?.lifecycle;
|
||||
if (lifecycle instanceof BackendLifecycleImpl) {
|
||||
await lifecycle.shutdown();
|
||||
} else {
|
||||
throw new Error('Unexpected lifecycle service implementation');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class BackstageBackend implements Backend {
|
||||
await this.#initializer.start();
|
||||
}
|
||||
|
||||
// async stop(): Promise<void> {
|
||||
// await this.#initializer.stop();
|
||||
// }
|
||||
async stop(): Promise<void> {
|
||||
await this.#initializer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import { BackstageBackend } from './BackstageBackend';
|
||||
export interface Backend {
|
||||
add(feature: BackendFeature): void;
|
||||
start(): Promise<void>;
|
||||
stop(): Promise<void>;
|
||||
}
|
||||
|
||||
export interface BackendRegisterInit {
|
||||
|
||||
Reference in New Issue
Block a user