Merge pull request #14985 from backstage/mob/pls-stop

backend-app-api, backend-test-utils: added backend.stop() and auto stop in tests
This commit is contained in:
Patrik Oldsberg
2022-12-15 01:06:52 +01:00
committed by GitHub
9 changed files with 154 additions and 8 deletions
+2
View File
@@ -25,6 +25,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,
coreServices,
ServiceRef,
} from '@backstage/backend-plugin-api';
import { BackendLifecycleImpl } from '../services/implementations/lifecycleService';
import {
BackendRegisterInit,
EnumerableServiceHolder,
@@ -173,4 +175,23 @@ export class BackendInitializer {
return orderedRegisterInits;
}
async stop(): Promise<void> {
if (!this.#started) {
return;
}
const lifecycleService = await this.#serviceHolder.get(
coreServices.lifecycle,
'root',
);
// TODO(Rugvip): Find a better way to do this
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 {