catalog: Reuse builder for next/legacy catalog

Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2021-06-14 16:10:18 +02:00
parent f8e773e3e9
commit f68632411b
3 changed files with 48 additions and 36 deletions
+2 -36
View File
@@ -14,13 +14,9 @@
* limitations under the License.
*/
import { useHotCleanup } from '@backstage/backend-common';
import {
CatalogBuilder,
createRouter,
NextCatalogBuilder,
runPeriodically,
createNextRouter,
} from '@backstage/plugin-catalog-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
@@ -28,36 +24,7 @@ import { PluginEnvironment } from '../types';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
/*
* This environment variable exists as an emergency option during the release
* of the new catalog processing engine.
* If you experience any issues, make sure to report them as this flag
* will be removed in a subsequent release.
*/
if (process.env.LEGACY_CATALOG === '1') {
const builder = new CatalogBuilder(env);
const {
entitiesCatalog,
locationsCatalog,
higherOrderOperation,
locationAnalyzer,
} = await builder.build();
useHotCleanup(
module,
runPeriodically(() => higherOrderOperation.refreshAllLocations(), 100000),
);
return await createRouter({
entitiesCatalog,
locationsCatalog,
higherOrderOperation,
locationAnalyzer,
logger: env.logger,
config: env.config,
});
}
const builder = new NextCatalogBuilder(env);
const builder = await CatalogBuilder.create(env);
const {
entitiesCatalog,
locationAnalyzer,
@@ -65,10 +32,9 @@ export default async function createPlugin(
locationService,
} = await builder.build();
// TODO(jhaals): run and manage in background.
await processingEngine.start();
return await createNextRouter({
return await createRouter({
entitiesCatalog,
locationAnalyzer,
locationService,