feat: add missing lifecycle monitoring for catalog, search and server

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2024-03-27 16:08:20 +02:00
parent 9624efb688
commit c6cb568f39
6 changed files with 45 additions and 9 deletions
+17 -3
View File
@@ -22,11 +22,11 @@ import {
LoggerService,
} from '@backstage/backend-plugin-api';
import { DocumentTypeInfo } from '@backstage/plugin-search-common';
import {
IndexBuilder,
RegisterCollatorParameters,
RegisterDecoratorParameters,
Scheduler,
SearchEngine,
} from '@backstage/plugin-search-backend-node';
@@ -49,6 +49,11 @@ export interface SearchIndexService {
* Starts indexing process
*/
start(options: SearchIndexServiceStartOptions): Promise<void>;
/**
* Stops indexing process
*/
stop(): Promise<void>;
/**
* Returns an index types list.
*/
@@ -81,8 +86,9 @@ type DefaultSearchIndexServiceOptions = {
* Reponsible for register the indexing task and start the schedule.
*/
class DefaultSearchIndexService implements SearchIndexService {
private logger: LoggerService;
private readonly logger: LoggerService;
private indexBuilder: IndexBuilder | null = null;
private scheduler: Scheduler | null = null;
private constructor(options: DefaultSearchIndexServiceOptions) {
this.logger = options.logger;
@@ -107,7 +113,15 @@ class DefaultSearchIndexService implements SearchIndexService {
);
const { scheduler } = await this.indexBuilder?.build();
scheduler.start();
this.scheduler = scheduler;
this.scheduler!.start();
}
async stop(): Promise<void> {
if (this.scheduler) {
this.scheduler.stop();
this.scheduler = null;
}
}
getDocumentTypes(): Record<string, DocumentTypeInfo> {