@backstage-community/plugin-tech-insights-backend 1.2.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/index.d.ts +13 -6
- package/dist/plugin/plugin.cjs.js +6 -3
- package/dist/plugin/plugin.cjs.js.map +1 -1
- package/dist/service/fact/FactRetrieverEngine.cjs.js +22 -15
- package/dist/service/fact/FactRetrieverEngine.cjs.js.map +1 -1
- package/dist/service/techInsightsContextBuilder.cjs.js +4 -2
- package/dist/service/techInsightsContextBuilder.cjs.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @backstage-community/plugin-tech-insights-backend
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- c3bbe0f: In order to use UrlReaderService in fact retrievers, UrlReaderService has been added to FactRetrieverContext.
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 306121a: Allow tech insights backend to schedule a single job.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [c3bbe0f]
|
|
16
|
+
- @backstage-community/plugin-tech-insights-node@2.0.0
|
|
17
|
+
|
|
3
18
|
## 1.2.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
-
import { LoggerService, DatabaseService, DiscoveryService, SchedulerService, AuthService } from '@backstage/backend-plugin-api';
|
|
2
|
+
import { LoggerService, DatabaseService, DiscoveryService, SchedulerService, AuthService, UrlReaderService } from '@backstage/backend-plugin-api';
|
|
3
3
|
import { FactRetrieverRegistry as FactRetrieverRegistry$1, PersistenceContext as PersistenceContext$1, FactRetriever, FactLifecycle, FactRetrieverRegistration, TechInsightCheck, FactChecker, FactCheckerFactory } from '@backstage-community/plugin-tech-insights-node';
|
|
4
4
|
import { HumanDuration } from '@backstage/types';
|
|
5
5
|
import { Duration } from 'luxon';
|
|
@@ -77,26 +77,32 @@ declare function createFactRetrieverRegistration(options: FactRetrieverRegistrat
|
|
|
77
77
|
*
|
|
78
78
|
* FactRetrieverEngine responsible scheduling and running fact retrieval tasks.
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
declare abstract class FactRetrieverEngine {
|
|
81
81
|
/**
|
|
82
82
|
* Schedules fact retriever run cycles based on configuration provided in the registration.
|
|
83
83
|
*
|
|
84
84
|
* Default implementation uses backend-tasks to handle scheduling. This function can be called multiple
|
|
85
85
|
* times, where initial calls schedule the tasks and subsequent invocations update the schedules.
|
|
86
86
|
*/
|
|
87
|
-
schedule(): Promise<void>;
|
|
87
|
+
abstract schedule(): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Schedules single fact retriever run cycles based on configuration provided in the registration.
|
|
90
|
+
*
|
|
91
|
+
* Default implementation defers to scheduling all jobs
|
|
92
|
+
*/
|
|
93
|
+
scheduleJob(_: string): Promise<void>;
|
|
88
94
|
/**
|
|
89
95
|
* Provides possibility to manually run a fact retriever job and construct fact data
|
|
90
96
|
*
|
|
91
97
|
* @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id
|
|
92
98
|
*/
|
|
93
|
-
triggerJob(ref: string): Promise<void>;
|
|
99
|
+
abstract triggerJob(ref: string): Promise<void>;
|
|
94
100
|
/**
|
|
95
101
|
* Exposes fact retriever job configuration information about previous and next runs and schedule
|
|
96
102
|
*
|
|
97
103
|
* @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id
|
|
98
104
|
*/
|
|
99
|
-
getJobRegistration(ref: string): Promise<FactRetrieverRegistration>;
|
|
105
|
+
abstract getJobRegistration(ref: string): Promise<FactRetrieverRegistration>;
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
/**
|
|
@@ -209,6 +215,7 @@ interface TechInsightsOptions<CheckType extends TechInsightCheck, CheckResultTyp
|
|
|
209
215
|
database: DatabaseService;
|
|
210
216
|
scheduler: SchedulerService;
|
|
211
217
|
auth: AuthService;
|
|
218
|
+
urlReader: UrlReaderService;
|
|
212
219
|
}
|
|
213
220
|
/**
|
|
214
221
|
* @public
|
|
@@ -234,4 +241,4 @@ type TechInsightsContext<CheckType extends TechInsightCheck, CheckResultType ext
|
|
|
234
241
|
*/
|
|
235
242
|
declare const buildTechInsightsContext: <CheckType extends TechInsightCheck, CheckResultType extends CheckResult>(options: TechInsightsOptions<CheckType, CheckResultType>) => Promise<TechInsightsContext<CheckType, CheckResultType>>;
|
|
236
243
|
|
|
237
|
-
export {
|
|
244
|
+
export { FactRetrieverEngine, type FactRetrieverRegistrationOptions, type FactRetrieverRegistry, type PersistenceContext, type PersistenceContextOptions, type RouterOptions, type TechInsightsContext, type TechInsightsOptions, buildTechInsightsContext, createFactRetrieverRegistration, createRouter, techInsightsPlugin as default, entityMetadataFactRetriever, entityOwnershipFactRetriever, initializePersistenceContext, techdocsFactRetriever };
|
|
@@ -54,7 +54,8 @@ const techInsightsPlugin = backendPluginApi.createBackendPlugin({
|
|
|
54
54
|
httpRouter: backendPluginApi.coreServices.httpRouter,
|
|
55
55
|
logger: backendPluginApi.coreServices.logger,
|
|
56
56
|
scheduler: backendPluginApi.coreServices.scheduler,
|
|
57
|
-
auth: backendPluginApi.coreServices.auth
|
|
57
|
+
auth: backendPluginApi.coreServices.auth,
|
|
58
|
+
urlReader: backendPluginApi.coreServices.urlReader
|
|
58
59
|
},
|
|
59
60
|
async init({
|
|
60
61
|
config: config$1,
|
|
@@ -63,7 +64,8 @@ const techInsightsPlugin = backendPluginApi.createBackendPlugin({
|
|
|
63
64
|
httpRouter,
|
|
64
65
|
logger,
|
|
65
66
|
scheduler,
|
|
66
|
-
auth
|
|
67
|
+
auth,
|
|
68
|
+
urlReader
|
|
67
69
|
}) {
|
|
68
70
|
const factRetrievers = Object.entries(
|
|
69
71
|
addedFactRetrievers
|
|
@@ -84,7 +86,8 @@ const techInsightsPlugin = backendPluginApi.createBackendPlugin({
|
|
|
84
86
|
logger,
|
|
85
87
|
persistenceContext,
|
|
86
88
|
scheduler,
|
|
87
|
-
auth
|
|
89
|
+
auth,
|
|
90
|
+
urlReader
|
|
88
91
|
});
|
|
89
92
|
httpRouter.use(
|
|
90
93
|
await router.createRouter({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["../../src/plugin/plugin.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { CheckResult } from '@backstage-community/plugin-tech-insights-common';\nimport {\n FactCheckerFactory,\n FactRetriever,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n PersistenceContext,\n TechInsightCheck,\n techInsightsFactCheckerFactoryExtensionPoint,\n techInsightsFactRetrieverRegistryExtensionPoint,\n techInsightsFactRetrieversExtensionPoint,\n techInsightsPersistenceContextExtensionPoint,\n} from '@backstage-community/plugin-tech-insights-node';\nimport {\n buildTechInsightsContext,\n createRouter,\n entityMetadataFactRetriever,\n entityOwnershipFactRetriever,\n techdocsFactRetriever,\n} from '../service';\nimport { createFactRetrieverRegistrationFromConfig } from './config';\n\n/**\n * The tech-insights backend plugin.\n *\n * @public\n */\nexport const techInsightsPlugin = createBackendPlugin({\n pluginId: 'tech-insights',\n register(env) {\n let factCheckerFactory:\n | FactCheckerFactory<TechInsightCheck, CheckResult>\n | undefined = undefined;\n env.registerExtensionPoint(techInsightsFactCheckerFactoryExtensionPoint, {\n setFactCheckerFactory<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n >(factory: FactCheckerFactory<CheckType, CheckResultType>): void {\n factCheckerFactory = factory;\n },\n });\n\n let factRetrieverRegistry: FactRetrieverRegistry | undefined = undefined;\n env.registerExtensionPoint(\n techInsightsFactRetrieverRegistryExtensionPoint,\n {\n setFactRetrieverRegistry(registry: FactRetrieverRegistry): void {\n factRetrieverRegistry = registry;\n },\n },\n );\n\n // initialized with built-in fact retrievers\n // only added as registration if there is config for them\n const addedFactRetrievers: Record<string, FactRetriever> = {\n entityMetadataFactRetriever,\n entityOwnershipFactRetriever,\n techdocsFactRetriever,\n };\n env.registerExtensionPoint(techInsightsFactRetrieversExtensionPoint, {\n addFactRetrievers(factRetrievers: Record<string, FactRetriever>): void {\n Object.entries(factRetrievers).forEach(([key, value]) => {\n addedFactRetrievers[key] = value;\n });\n },\n });\n\n let persistenceContext: PersistenceContext | undefined = undefined;\n env.registerExtensionPoint(techInsightsPersistenceContextExtensionPoint, {\n setPersistenceContext(context: PersistenceContext): void {\n persistenceContext = context;\n },\n });\n\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n database: coreServices.database,\n discovery: coreServices.discovery,\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n auth: coreServices.auth,\n },\n async init({\n config,\n database,\n discovery,\n httpRouter,\n logger,\n scheduler,\n auth,\n }) {\n const factRetrievers: FactRetrieverRegistration[] = Object.entries(\n addedFactRetrievers,\n )\n .map(([name, factRetriever]) =>\n createFactRetrieverRegistrationFromConfig(\n config,\n name,\n factRetriever,\n ),\n )\n .filter(registration => registration) as FactRetrieverRegistration[];\n\n const context = await buildTechInsightsContext({\n config,\n database,\n discovery,\n factCheckerFactory,\n factRetrieverRegistry,\n factRetrievers,\n logger,\n persistenceContext,\n scheduler,\n auth,\n });\n\n httpRouter.use(\n await createRouter({\n ...context,\n config,\n logger,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendPlugin","techInsightsFactCheckerFactoryExtensionPoint","techInsightsFactRetrieverRegistryExtensionPoint","entityMetadataFactRetriever","entityOwnershipFactRetriever","techdocsFactRetriever","techInsightsFactRetrieversExtensionPoint","techInsightsPersistenceContextExtensionPoint","coreServices","config","createFactRetrieverRegistrationFromConfig","buildTechInsightsContext","createRouter"],"mappings":";;;;;;;;;;;;AA+CO,MAAM,qBAAqBA,oCAAoB,CAAA;AAAA,EACpD,QAAU,EAAA,eAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,IAAI,kBAEY,GAAA,KAAA,CAAA,CAAA;AAChB,IAAA,GAAA,CAAI,uBAAuBC,mEAA8C,EAAA;AAAA,MACvE,sBAGE,OAA+D,EAAA;AAC/D,QAAqB,kBAAA,GAAA,OAAA,CAAA;AAAA,OACvB;AAAA,KACD,CAAA,CAAA;AAED,IAAA,IAAI,qBAA2D,GAAA,KAAA,CAAA,CAAA;AAC/D,IAAI,GAAA,CAAA,sBAAA;AAAA,MACFC,sEAAA;AAAA,MACA;AAAA,QACE,yBAAyB,QAAuC,EAAA;AAC9D,UAAwB,qBAAA,GAAA,QAAA,CAAA;AAAA,SAC1B;AAAA,OACF;AAAA,KACF,CAAA;AAIA,IAAA,MAAM,mBAAqD,GAAA;AAAA,mCACzDC,uDAAA;AAAA,oCACAC,yDAAA;AAAA,6BACAC,2CAAA;AAAA,KACF,CAAA;AACA,IAAA,GAAA,CAAI,uBAAuBC,+DAA0C,EAAA;AAAA,MACnE,kBAAkB,cAAqD,EAAA;AACrE,QAAO,MAAA,CAAA,OAAA,CAAQ,cAAc,CAAE,CAAA,OAAA,CAAQ,CAAC,CAAC,GAAA,EAAK,KAAK,CAAM,KAAA;AACvD,UAAA,mBAAA,CAAoB,GAAG,CAAI,GAAA,KAAA,CAAA;AAAA,SAC5B,CAAA,CAAA;AAAA,OACH;AAAA,KACD,CAAA,CAAA;AAED,IAAA,IAAI,kBAAqD,GAAA,KAAA,CAAA,CAAA;AACzD,IAAA,GAAA,CAAI,uBAAuBC,mEAA8C,EAAA;AAAA,MACvE,sBAAsB,OAAmC,EAAA;AACvD,QAAqB,kBAAA,GAAA,OAAA,CAAA;AAAA,OACvB;AAAA,KACD,CAAA,CAAA;AAED,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,UAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,MAAMA,6BAAa,CAAA,IAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../../src/plugin/plugin.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { CheckResult } from '@backstage-community/plugin-tech-insights-common';\nimport {\n FactCheckerFactory,\n FactRetriever,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n PersistenceContext,\n TechInsightCheck,\n techInsightsFactCheckerFactoryExtensionPoint,\n techInsightsFactRetrieverRegistryExtensionPoint,\n techInsightsFactRetrieversExtensionPoint,\n techInsightsPersistenceContextExtensionPoint,\n} from '@backstage-community/plugin-tech-insights-node';\nimport {\n buildTechInsightsContext,\n createRouter,\n entityMetadataFactRetriever,\n entityOwnershipFactRetriever,\n techdocsFactRetriever,\n} from '../service';\nimport { createFactRetrieverRegistrationFromConfig } from './config';\n\n/**\n * The tech-insights backend plugin.\n *\n * @public\n */\nexport const techInsightsPlugin = createBackendPlugin({\n pluginId: 'tech-insights',\n register(env) {\n let factCheckerFactory:\n | FactCheckerFactory<TechInsightCheck, CheckResult>\n | undefined = undefined;\n env.registerExtensionPoint(techInsightsFactCheckerFactoryExtensionPoint, {\n setFactCheckerFactory<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n >(factory: FactCheckerFactory<CheckType, CheckResultType>): void {\n factCheckerFactory = factory;\n },\n });\n\n let factRetrieverRegistry: FactRetrieverRegistry | undefined = undefined;\n env.registerExtensionPoint(\n techInsightsFactRetrieverRegistryExtensionPoint,\n {\n setFactRetrieverRegistry(registry: FactRetrieverRegistry): void {\n factRetrieverRegistry = registry;\n },\n },\n );\n\n // initialized with built-in fact retrievers\n // only added as registration if there is config for them\n const addedFactRetrievers: Record<string, FactRetriever> = {\n entityMetadataFactRetriever,\n entityOwnershipFactRetriever,\n techdocsFactRetriever,\n };\n env.registerExtensionPoint(techInsightsFactRetrieversExtensionPoint, {\n addFactRetrievers(factRetrievers: Record<string, FactRetriever>): void {\n Object.entries(factRetrievers).forEach(([key, value]) => {\n addedFactRetrievers[key] = value;\n });\n },\n });\n\n let persistenceContext: PersistenceContext | undefined = undefined;\n env.registerExtensionPoint(techInsightsPersistenceContextExtensionPoint, {\n setPersistenceContext(context: PersistenceContext): void {\n persistenceContext = context;\n },\n });\n\n env.registerInit({\n deps: {\n config: coreServices.rootConfig,\n database: coreServices.database,\n discovery: coreServices.discovery,\n httpRouter: coreServices.httpRouter,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n auth: coreServices.auth,\n urlReader: coreServices.urlReader,\n },\n async init({\n config,\n database,\n discovery,\n httpRouter,\n logger,\n scheduler,\n auth,\n urlReader,\n }) {\n const factRetrievers: FactRetrieverRegistration[] = Object.entries(\n addedFactRetrievers,\n )\n .map(([name, factRetriever]) =>\n createFactRetrieverRegistrationFromConfig(\n config,\n name,\n factRetriever,\n ),\n )\n .filter(registration => registration) as FactRetrieverRegistration[];\n\n const context = await buildTechInsightsContext({\n config,\n database,\n discovery,\n factCheckerFactory,\n factRetrieverRegistry,\n factRetrievers,\n logger,\n persistenceContext,\n scheduler,\n auth,\n urlReader,\n });\n\n httpRouter.use(\n await createRouter({\n ...context,\n config,\n logger,\n }),\n );\n },\n });\n },\n});\n"],"names":["createBackendPlugin","techInsightsFactCheckerFactoryExtensionPoint","techInsightsFactRetrieverRegistryExtensionPoint","entityMetadataFactRetriever","entityOwnershipFactRetriever","techdocsFactRetriever","techInsightsFactRetrieversExtensionPoint","techInsightsPersistenceContextExtensionPoint","coreServices","config","createFactRetrieverRegistrationFromConfig","buildTechInsightsContext","createRouter"],"mappings":";;;;;;;;;;;;AA+CO,MAAM,qBAAqBA,oCAAoB,CAAA;AAAA,EACpD,QAAU,EAAA,eAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,IAAI,kBAEY,GAAA,KAAA,CAAA,CAAA;AAChB,IAAA,GAAA,CAAI,uBAAuBC,mEAA8C,EAAA;AAAA,MACvE,sBAGE,OAA+D,EAAA;AAC/D,QAAqB,kBAAA,GAAA,OAAA,CAAA;AAAA,OACvB;AAAA,KACD,CAAA,CAAA;AAED,IAAA,IAAI,qBAA2D,GAAA,KAAA,CAAA,CAAA;AAC/D,IAAI,GAAA,CAAA,sBAAA;AAAA,MACFC,sEAAA;AAAA,MACA;AAAA,QACE,yBAAyB,QAAuC,EAAA;AAC9D,UAAwB,qBAAA,GAAA,QAAA,CAAA;AAAA,SAC1B;AAAA,OACF;AAAA,KACF,CAAA;AAIA,IAAA,MAAM,mBAAqD,GAAA;AAAA,mCACzDC,uDAAA;AAAA,oCACAC,yDAAA;A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aAAa,CACxB,KAAAC,gDAAA;AAAA,YACED,QAAA;AAAA,YACA,IAAA;AAAA,YACA,aAAA;AAAA,WACF;AAAA,SACF,CACC,MAAO,CAAA,CAAA,YAAA,KAAgB,YAAY,CAAA,CAAA;AAEtC,QAAM,MAAA,OAAA,GAAU,MAAME,mDAAyB,CAAA;AAAA,kBAC7CF,QAAA;AAAA,UACA,QAAA;AAAA,UACA,SAAA;AAAA,UACA,kBAAA;AAAA,UACA,qBAAA;AAAA,UACA,cAAA;AAAA,UACA,MAAA;AAAA,UACA,kBAAA;AAAA,UACA,SAAA;AAAA,UACA,IAAA;AAAA,UACA,SAAA;AAAA,SACD,CAAA,CAAA;AAED,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMG,mBAAa,CAAA;AAAA,YACjB,GAAG,OAAA;AAAA,oBACHH,QAAA;AAAA,YACA,MAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
|
|
@@ -45,29 +45,36 @@ class DefaultFactRetrieverEngine {
|
|
|
45
45
|
defaultInitialDelay
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
|
+
async scheduleRegistration(registration) {
|
|
49
|
+
const { factRetriever, cadence, lifecycle, timeout, initialDelay } = registration;
|
|
50
|
+
const cronExpression = cadence || this.defaultCadence || randomDailyCron();
|
|
51
|
+
const timeLimit = timeout || this.defaultTimeout || luxon.Duration.fromObject({ minutes: 5 });
|
|
52
|
+
const initialDelaySetting = initialDelay || this.defaultInitialDelay || luxon.Duration.fromObject({ seconds: 5 });
|
|
53
|
+
await this.scheduler.scheduleTask({
|
|
54
|
+
id: factRetriever.id,
|
|
55
|
+
frequency: { cron: cronExpression },
|
|
56
|
+
fn: this.createFactRetrieverHandler(factRetriever, lifecycle),
|
|
57
|
+
timeout: timeLimit,
|
|
58
|
+
// We add a delay in order to prevent errors due to the
|
|
59
|
+
// fact that the backend is not yet online in a cold-start scenario
|
|
60
|
+
initialDelay: initialDelaySetting
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async scheduleJob(ref) {
|
|
64
|
+
const registration = await this.factRetrieverRegistry.get(ref);
|
|
65
|
+
return this.scheduleRegistration(registration);
|
|
66
|
+
}
|
|
48
67
|
async schedule() {
|
|
49
68
|
const registrations = await this.factRetrieverRegistry.listRegistrations();
|
|
50
69
|
const newRegs = [];
|
|
51
70
|
await Promise.all(
|
|
52
71
|
registrations.map(async (registration) => {
|
|
53
|
-
const { factRetriever, cadence, lifecycle, timeout, initialDelay } = registration;
|
|
54
|
-
const cronExpression = cadence || this.defaultCadence || randomDailyCron();
|
|
55
|
-
const timeLimit = timeout || this.defaultTimeout || luxon.Duration.fromObject({ minutes: 5 });
|
|
56
|
-
const initialDelaySetting = initialDelay || this.defaultInitialDelay || luxon.Duration.fromObject({ seconds: 5 });
|
|
57
72
|
try {
|
|
58
|
-
await this.
|
|
59
|
-
|
|
60
|
-
frequency: { cron: cronExpression },
|
|
61
|
-
fn: this.createFactRetrieverHandler(factRetriever, lifecycle),
|
|
62
|
-
timeout: timeLimit,
|
|
63
|
-
// We add a delay in order to prevent errors due to the
|
|
64
|
-
// fact that the backend is not yet online in a cold-start scenario
|
|
65
|
-
initialDelay: initialDelaySetting
|
|
66
|
-
});
|
|
67
|
-
newRegs.push(factRetriever.id);
|
|
73
|
+
await this.scheduleRegistration(registration);
|
|
74
|
+
newRegs.push(registration.factRetriever.id);
|
|
68
75
|
} catch (e) {
|
|
69
76
|
this.logger.warn(
|
|
70
|
-
`Failed to schedule fact retriever ${factRetriever.id}, ${e}`
|
|
77
|
+
`Failed to schedule fact retriever ${registration.factRetriever.id}, ${e}`
|
|
71
78
|
);
|
|
72
79
|
}
|
|
73
80
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FactRetrieverEngine.cjs.js","sources":["../../../src/service/fact/FactRetrieverEngine.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n FactLifecycle,\n FactRetriever,\n FactRetrieverContext,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n TechInsightFact,\n TechInsightsStore,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { Duration } from 'luxon';\nimport { LoggerService, SchedulerService } from '@backstage/backend-plugin-api';\n\nfunction randomDailyCron() {\n const rand = (min: number, max: number) =>\n Math.floor(Math.random() * (max - min + 1) + min);\n return `${rand(0, 59)} ${rand(0, 23)} * * *`;\n}\n\nfunction duration(startTimestamp: [number, number]): string {\n const delta = process.hrtime(startTimestamp);\n const seconds = delta[0] + delta[1] / 1e9;\n return `${seconds.toFixed(1)}s`;\n}\n\n/**\n * @public\n *\n * FactRetrieverEngine responsible scheduling and running fact retrieval tasks.\n */\nexport interface FactRetrieverEngine {\n /**\n * Schedules fact retriever run cycles based on configuration provided in the registration.\n *\n * Default implementation uses backend-tasks to handle scheduling. This function can be called multiple\n * times, where initial calls schedule the tasks and subsequent invocations update the schedules.\n */\n schedule(): Promise<void>;\n\n /**\n * Provides possibility to manually run a fact retriever job and construct fact data\n *\n * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id\n */\n triggerJob(ref: string): Promise<void>;\n\n /**\n * Exposes fact retriever job configuration information about previous and next runs and schedule\n *\n * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id\n */\n getJobRegistration(ref: string): Promise<FactRetrieverRegistration>;\n}\n\nexport class DefaultFactRetrieverEngine implements FactRetrieverEngine {\n private constructor(\n private readonly repository: TechInsightsStore,\n private readonly factRetrieverRegistry: FactRetrieverRegistry,\n private readonly factRetrieverContext: FactRetrieverContext,\n private readonly logger: LoggerService,\n private readonly scheduler: SchedulerService,\n private readonly defaultCadence?: string,\n private readonly defaultTimeout?: Duration,\n private readonly defaultInitialDelay?: Duration,\n ) {}\n\n static async create(options: {\n repository: TechInsightsStore;\n factRetrieverRegistry: FactRetrieverRegistry;\n factRetrieverContext: FactRetrieverContext;\n scheduler: SchedulerService;\n defaultCadence?: string;\n defaultTimeout?: Duration;\n defaultInitialDelay?: Duration;\n }) {\n const {\n repository,\n factRetrieverRegistry,\n factRetrieverContext,\n scheduler,\n defaultCadence,\n defaultTimeout,\n defaultInitialDelay,\n } = options;\n\n const retrievers = await factRetrieverRegistry.listRetrievers();\n await Promise.all(retrievers.map(it => repository.insertFactSchema(it)));\n\n return new DefaultFactRetrieverEngine(\n repository,\n factRetrieverRegistry,\n factRetrieverContext,\n factRetrieverContext.logger,\n scheduler,\n defaultCadence,\n defaultTimeout,\n defaultInitialDelay,\n );\n }\n\n async schedule() {\n const registrations = await this.factRetrieverRegistry.listRegistrations();\n const newRegs: string[] = [];\n\n await Promise.all(\n registrations.map(async registration => {\n const { factRetriever, cadence, lifecycle, timeout, initialDelay } =\n registration;\n const cronExpression =\n cadence || this.defaultCadence || randomDailyCron();\n const timeLimit =\n timeout || this.defaultTimeout || Duration.fromObject({ minutes: 5 });\n const initialDelaySetting =\n initialDelay ||\n this.defaultInitialDelay ||\n Duration.fromObject({ seconds: 5 });\n try {\n await this.scheduler.scheduleTask({\n id: factRetriever.id,\n frequency: { cron: cronExpression },\n fn: this.createFactRetrieverHandler(factRetriever, lifecycle),\n timeout: timeLimit,\n // We add a delay in order to prevent errors due to the\n // fact that the backend is not yet online in a cold-start scenario\n initialDelay: initialDelaySetting,\n });\n newRegs.push(factRetriever.id);\n } catch (e) {\n this.logger.warn(\n `Failed to schedule fact retriever ${factRetriever.id}, ${e}`,\n );\n }\n }),\n );\n\n this.logger.info(\n `Scheduled ${newRegs.length}/${registrations.length} fact retrievers into the tech-insights engine`,\n );\n }\n\n getJobRegistration(ref: string): Promise<FactRetrieverRegistration> {\n return this.factRetrieverRegistry.get(ref);\n }\n\n async triggerJob(ref: string): Promise<void> {\n await this.scheduler.triggerTask(ref);\n }\n\n private createFactRetrieverHandler(\n factRetriever: FactRetriever,\n lifecycle?: FactLifecycle,\n ) {\n return async () => {\n const startTimestamp = process.hrtime();\n this.logger.info(\n `Retrieving facts for fact retriever ${factRetriever.id}`,\n );\n\n let facts: TechInsightFact[] = [];\n try {\n facts = await factRetriever.handler({\n ...this.factRetrieverContext,\n logger: this.logger.child({ factRetrieverId: factRetriever.id }),\n entityFilter: factRetriever.entityFilter,\n });\n this.logger.debug(\n `Retrieved ${facts.length} facts for fact retriever ${\n factRetriever.id\n } in ${duration(startTimestamp)}`,\n );\n } catch (e) {\n this.logger.error(\n `Failed to retrieve facts for retriever ${factRetriever.id}`,\n e,\n );\n }\n\n try {\n await this.repository.insertFacts({\n id: factRetriever.id,\n facts,\n lifecycle,\n });\n this.logger.info(\n `Stored ${facts.length} facts for fact retriever ${\n factRetriever.id\n } in ${duration(startTimestamp)}`,\n );\n } catch (e) {\n this.logger.warn(\n `Failed to insert facts for fact retriever ${factRetriever.id}`,\n e,\n );\n }\n };\n }\n}\n"],"names":["Duration"],"mappings":";;;;AA2BA,SAAS,eAAkB,GAAA;AACzB,EAAA,MAAM,IAAO,GAAA,CAAC,GAAa,EAAA,GAAA,KACzB,IAAK,CAAA,KAAA,CAAM,IAAK,CAAA,MAAA,EAAY,IAAA,GAAA,GAAM,GAAM,GAAA,CAAA,CAAA,GAAK,GAAG,CAAA,CAAA;AAClD,EAAO,OAAA,CAAA,EAAG,KAAK,CAAG,EAAA,EAAE,CAAC,CAAI,CAAA,EAAA,IAAA,CAAK,CAAG,EAAA,EAAE,CAAC,CAAA,MAAA,CAAA,CAAA;AACtC,CAAA;AAEA,SAAS,SAAS,cAA0C,EAAA;AAC1D,EAAM,MAAA,KAAA,GAAQ,OAA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AA,EACvB,cAAc,EAChB,CAAA,IAAA,EAAO,QAAS,CAAA,cAAc,CAAC,CAAA,CAAA;AAAA,SACjC,CAAA;AAAA,eACO,CAAG,EAAA;AACV,QAAA,IAAA,CAAK,MAAO,CAAA,KAAA;AAAA,UACV,CAAA,uCAAA,EAA0C,cAAc,EAAE,CAAA,CAAA;AAAA,UAC1D,CAAA;AAAA,SACF,CAAA;AAAA,OACF;AAEA,MAAI,IAAA;AACF,QAAM,MAAA,IAAA,CAAK,WAAW,WAAY,CAAA;AAAA,UAChC,IAAI,aAAc,CAAA,EAAA;AAAA,UAClB,KAAA;AAAA,UACA,SAAA;AAAA,SACD,CAAA,CAAA;AACD,QAAA,IAAA,CAAK,MAAO,CAAA,IAAA;AAAA,UACV,CAAA,OAAA,EAAU,MAAM,MAAM,CAAA,0BAAA,EACpB,cAAc,EAChB,CAAA,IAAA,EAAO,QAAS,CAAA,cAAc,CAAC,CAAA,CAAA;AAAA,SACjC,CAAA;AAAA,eACO,CAAG,EAAA;AACV,QAAA,IAAA,CAAK,MAAO,CAAA,IAAA;AAAA,UACV,CAAA,0CAAA,EAA6C,cAAc,EAAE,CAAA,CAAA;AAAA,UAC7D,CAAA;AAAA,SACF,CAAA;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"FactRetrieverEngine.cjs.js","sources":["../../../src/service/fact/FactRetrieverEngine.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n FactLifecycle,\n FactRetriever,\n FactRetrieverContext,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n TechInsightFact,\n TechInsightsStore,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { Duration } from 'luxon';\nimport { LoggerService, SchedulerService } from '@backstage/backend-plugin-api';\n\nfunction randomDailyCron() {\n const rand = (min: number, max: number) =>\n Math.floor(Math.random() * (max - min + 1) + min);\n return `${rand(0, 59)} ${rand(0, 23)} * * *`;\n}\n\nfunction duration(startTimestamp: [number, number]): string {\n const delta = process.hrtime(startTimestamp);\n const seconds = delta[0] + delta[1] / 1e9;\n return `${seconds.toFixed(1)}s`;\n}\n\n/**\n * @public\n *\n * FactRetrieverEngine responsible scheduling and running fact retrieval tasks.\n */\nexport abstract class FactRetrieverEngine {\n /**\n * Schedules fact retriever run cycles based on configuration provided in the registration.\n *\n * Default implementation uses backend-tasks to handle scheduling. This function can be called multiple\n * times, where initial calls schedule the tasks and subsequent invocations update the schedules.\n */\n abstract schedule(): Promise<void>;\n\n /**\n * Schedules single fact retriever run cycles based on configuration provided in the registration.\n *\n * Default implementation defers to scheduling all jobs\n */\n async scheduleJob(_: string): Promise<void> {\n return await this.schedule();\n }\n\n /**\n * Provides possibility to manually run a fact retriever job and construct fact data\n *\n * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id\n */\n abstract triggerJob(ref: string): Promise<void>;\n\n /**\n * Exposes fact retriever job configuration information about previous and next runs and schedule\n *\n * @param ref - Reference to the task name stored in the executor database. By convention this is the fact retriever id\n */\n abstract getJobRegistration(ref: string): Promise<FactRetrieverRegistration>;\n}\n\nexport class DefaultFactRetrieverEngine implements FactRetrieverEngine {\n private constructor(\n private readonly repository: TechInsightsStore,\n private readonly factRetrieverRegistry: FactRetrieverRegistry,\n private readonly factRetrieverContext: FactRetrieverContext,\n private readonly logger: LoggerService,\n private readonly scheduler: SchedulerService,\n private readonly defaultCadence?: string,\n private readonly defaultTimeout?: Duration,\n private readonly defaultInitialDelay?: Duration,\n ) {}\n\n static async create(options: {\n repository: TechInsightsStore;\n factRetrieverRegistry: FactRetrieverRegistry;\n factRetrieverContext: FactRetrieverContext;\n scheduler: SchedulerService;\n defaultCadence?: string;\n defaultTimeout?: Duration;\n defaultInitialDelay?: Duration;\n }) {\n const {\n repository,\n factRetrieverRegistry,\n factRetrieverContext,\n scheduler,\n defaultCadence,\n defaultTimeout,\n defaultInitialDelay,\n } = options;\n\n const retrievers = await factRetrieverRegistry.listRetrievers();\n await Promise.all(retrievers.map(it => repository.insertFactSchema(it)));\n\n return new DefaultFactRetrieverEngine(\n repository,\n factRetrieverRegistry,\n factRetrieverContext,\n factRetrieverContext.logger,\n scheduler,\n defaultCadence,\n defaultTimeout,\n defaultInitialDelay,\n );\n }\n\n private async scheduleRegistration(registration: FactRetrieverRegistration) {\n const { factRetriever, cadence, lifecycle, timeout, initialDelay } =\n registration;\n const cronExpression = cadence || this.defaultCadence || randomDailyCron();\n const timeLimit =\n timeout || this.defaultTimeout || Duration.fromObject({ minutes: 5 });\n const initialDelaySetting =\n initialDelay ||\n this.defaultInitialDelay ||\n Duration.fromObject({ seconds: 5 });\n\n await this.scheduler.scheduleTask({\n id: factRetriever.id,\n frequency: { cron: cronExpression },\n fn: this.createFactRetrieverHandler(factRetriever, lifecycle),\n timeout: timeLimit,\n // We add a delay in order to prevent errors due to the\n // fact that the backend is not yet online in a cold-start scenario\n initialDelay: initialDelaySetting,\n });\n }\n\n async scheduleJob(ref: string): Promise<void> {\n const registration = await this.factRetrieverRegistry.get(ref);\n return this.scheduleRegistration(registration);\n }\n\n async schedule() {\n const registrations = await this.factRetrieverRegistry.listRegistrations();\n const newRegs: string[] = [];\n\n await Promise.all(\n registrations.map(async registration => {\n try {\n await this.scheduleRegistration(registration);\n newRegs.push(registration.factRetriever.id);\n } catch (e) {\n this.logger.warn(\n `Failed to schedule fact retriever ${registration.factRetriever.id}, ${e}`,\n );\n }\n }),\n );\n\n this.logger.info(\n `Scheduled ${newRegs.length}/${registrations.length} fact retrievers into the tech-insights engine`,\n );\n }\n\n getJobRegistration(ref: string): Promise<FactRetrieverRegistration> {\n return this.factRetrieverRegistry.get(ref);\n }\n\n async triggerJob(ref: string): Promise<void> {\n await this.scheduler.triggerTask(ref);\n }\n\n private createFactRetrieverHandler(\n factRetriever: FactRetriever,\n lifecycle?: FactLifecycle,\n ) {\n return async () => {\n const startTimestamp = process.hrtime();\n this.logger.info(\n `Retrieving facts for fact retriever ${factRetriever.id}`,\n );\n\n let facts: TechInsightFact[] = [];\n try {\n facts = await factRetriever.handler({\n ...this.factRetrieverContext,\n logger: this.logger.child({ factRetrieverId: factRetriever.id }),\n entityFilter: factRetriever.entityFilter,\n });\n this.logger.debug(\n `Retrieved ${facts.length} facts for fact retriever ${\n factRetriever.id\n } in ${duration(startTimestamp)}`,\n );\n } catch (e) {\n this.logger.error(\n `Failed to retrieve facts for retriever ${factRetriever.id}`,\n e,\n );\n }\n\n try {\n await this.repository.insertFacts({\n id: factRetriever.id,\n facts,\n lifecycle,\n });\n this.logger.info(\n `Stored ${facts.length} facts for fact retriever ${\n factRetriever.id\n } in ${duration(startTimestamp)}`,\n );\n } catch (e) {\n this.logger.warn(\n `Failed to insert facts for fact retriever ${factRetriever.id}`,\n e,\n );\n }\n };\n }\n}\n"],"names":["Duration"],"mappings":";;;;AA2BA,SAAS,eAAkB,GAAA;AACzB,EAAA,MAAM,IAAO,GAAA,CAAC,GAAa,EAAA,GAAA,KACzB,IAAK,CAAA,KAAA,CAAM,IAAK,CAAA,MAAA,EAAY,IAAA,GAAA,GAAM,GAAM,GAAA,CAAA,CAAA,GAAK,GAAG,CAAA,CAAA;AAClD,EAAO,OAAA,CAAA,EAAG,KAAK,CAAG,EAAA,EAAE,CAAC,CAAI,CAAA,EAAA,IAAA,CAAK,CAAG,EAAA,EAAE,CAAC,CAAA,MAAA,CAAA,CAAA;AACtC,CAAA;AAEA,SAAS,SAAS,cAA0C,EAAA;AAC1D,EAAM,MAAA,KAAA,GAAQ,OAAQ,CAAA,MAAA,CAAO,cAAc,CAAA,CAA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
|
|
17
|
+
urlReader
|
|
17
18
|
} = options;
|
|
18
19
|
const buildFactRetrieverRegistry = () => {
|
|
19
20
|
if (!options.factRetrieverRegistry) {
|
|
@@ -38,7 +39,8 @@ const buildTechInsightsContext = async (options) => {
|
|
|
38
39
|
config,
|
|
39
40
|
discovery,
|
|
40
41
|
logger,
|
|
41
|
-
auth
|
|
42
|
+
auth,
|
|
43
|
+
urlReader
|
|
42
44
|
}
|
|
43
45
|
});
|
|
44
46
|
await factRetrieverEngine.schedule();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"techInsightsContextBuilder.cjs.js","sources":["../../src/service/techInsightsContextBuilder.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DefaultFactRetrieverEngine,\n FactRetrieverEngine,\n} from './fact/FactRetrieverEngine';\nimport { DefaultFactRetrieverRegistry } from './fact/FactRetrieverRegistry';\nimport { Config } from '@backstage/config';\nimport {\n FactChecker,\n FactCheckerFactory,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n PersistenceContext,\n TechInsightCheck,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { initializePersistenceContext } from './persistence';\nimport { CheckResult } from '@backstage-community/plugin-tech-insights-common';\nimport {\n AuthService,\n DatabaseService,\n DiscoveryService,\n LoggerService,\n SchedulerService,\n} from '@backstage/backend-plugin-api';\n\n/**\n * @public\n * @typeParam CheckType - Type of the check for the fact checker this builder returns\n * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns\n *\n * Configuration options to initialize TechInsightsBuilder. Generic types params are needed if FactCheckerFactory\n * is included for FactChecker creation.\n */\nexport interface TechInsightsOptions<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n> {\n /**\n * Optional collection of FactRetrieverRegistrations (required if no factRetrieverRegistry passed in).\n * Used to register FactRetrievers and their schemas and schedule an execution loop for them.\n *\n * Not needed if passing in your own FactRetrieverRegistry implementation. Required otherwise.\n */\n factRetrievers?: FactRetrieverRegistration[];\n\n /**\n * Optional factory exposing a `construct` method to initialize a FactChecker implementation\n */\n factCheckerFactory?: FactCheckerFactory<CheckType, CheckResultType>;\n\n /**\n * Optional FactRetrieverRegistry implementation that replaces the default one.\n *\n * If passing this in you don't need to pass in factRetrievers also.\n */\n factRetrieverRegistry?: FactRetrieverRegistry;\n\n /**\n * Optional persistenceContext implementation that replaces the default one.\n * This can be used to replace underlying database with a more suitable implementation if needed\n */\n persistenceContext?: PersistenceContext;\n\n logger: LoggerService;\n config: Config;\n discovery: DiscoveryService;\n database: DatabaseService;\n scheduler: SchedulerService;\n auth: AuthService;\n}\n\n/**\n * @public\n * @typeParam CheckType - Type of the check for the fact checker this builder returns\n * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns\n *\n * A container for exported implementations related to TechInsights.\n * FactChecker is present if an optional FactCheckerFactory is included in the build stage.\n */\nexport type TechInsightsContext<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n> = {\n factChecker?: FactChecker<CheckType, CheckResultType>;\n persistenceContext: PersistenceContext;\n factRetrieverEngine: FactRetrieverEngine;\n};\n\n/**\n * @public\n *\n * Constructs needed persistence context, fact retriever engine\n * and optionally fact checker implementations to be used in the tech insights module.\n *\n * @param options - Needed options to construct TechInsightsContext\n * @returns TechInsightsContext with persistence implementations and optionally an implementation of a FactChecker\n */\nexport const buildTechInsightsContext = async <\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n>(\n options: TechInsightsOptions<CheckType, CheckResultType>,\n): Promise<TechInsightsContext<CheckType, CheckResultType>> => {\n const {\n factRetrievers,\n factCheckerFactory,\n config,\n discovery,\n database,\n logger,\n scheduler,\n auth,\n } = options;\n\n const buildFactRetrieverRegistry = (): FactRetrieverRegistry => {\n if (!options.factRetrieverRegistry) {\n if (!factRetrievers) {\n throw new Error(\n 'Failed to build FactRetrieverRegistry because no factRetrievers found',\n );\n }\n return new DefaultFactRetrieverRegistry(factRetrievers);\n }\n return options.factRetrieverRegistry;\n };\n\n const factRetrieverRegistry = buildFactRetrieverRegistry();\n\n const persistenceContext =\n options.persistenceContext ??\n (await initializePersistenceContext(database, {\n logger,\n }));\n\n const factRetrieverEngine = await DefaultFactRetrieverEngine.create({\n scheduler,\n repository: persistenceContext.techInsightsStore,\n factRetrieverRegistry,\n factRetrieverContext: {\n config,\n discovery,\n logger,\n auth,\n },\n });\n\n await factRetrieverEngine.schedule();\n\n if (factCheckerFactory) {\n const factChecker = factCheckerFactory.construct(\n persistenceContext.techInsightsStore,\n );\n return {\n persistenceContext,\n factChecker,\n factRetrieverEngine,\n };\n }\n\n return {\n persistenceContext,\n factRetrieverEngine,\n };\n};\n"],"names":["DefaultFactRetrieverRegistry","persistenceContext","initializePersistenceContext","DefaultFactRetrieverEngine"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"techInsightsContextBuilder.cjs.js","sources":["../../src/service/techInsightsContextBuilder.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n DefaultFactRetrieverEngine,\n FactRetrieverEngine,\n} from './fact/FactRetrieverEngine';\nimport { DefaultFactRetrieverRegistry } from './fact/FactRetrieverRegistry';\nimport { Config } from '@backstage/config';\nimport {\n FactChecker,\n FactCheckerFactory,\n FactRetrieverRegistration,\n FactRetrieverRegistry,\n PersistenceContext,\n TechInsightCheck,\n} from '@backstage-community/plugin-tech-insights-node';\nimport { initializePersistenceContext } from './persistence';\nimport { CheckResult } from '@backstage-community/plugin-tech-insights-common';\nimport {\n AuthService,\n DatabaseService,\n DiscoveryService,\n LoggerService,\n SchedulerService,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\n\n/**\n * @public\n * @typeParam CheckType - Type of the check for the fact checker this builder returns\n * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns\n *\n * Configuration options to initialize TechInsightsBuilder. Generic types params are needed if FactCheckerFactory\n * is included for FactChecker creation.\n */\nexport interface TechInsightsOptions<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n> {\n /**\n * Optional collection of FactRetrieverRegistrations (required if no factRetrieverRegistry passed in).\n * Used to register FactRetrievers and their schemas and schedule an execution loop for them.\n *\n * Not needed if passing in your own FactRetrieverRegistry implementation. Required otherwise.\n */\n factRetrievers?: FactRetrieverRegistration[];\n\n /**\n * Optional factory exposing a `construct` method to initialize a FactChecker implementation\n */\n factCheckerFactory?: FactCheckerFactory<CheckType, CheckResultType>;\n\n /**\n * Optional FactRetrieverRegistry implementation that replaces the default one.\n *\n * If passing this in you don't need to pass in factRetrievers also.\n */\n factRetrieverRegistry?: FactRetrieverRegistry;\n\n /**\n * Optional persistenceContext implementation that replaces the default one.\n * This can be used to replace underlying database with a more suitable implementation if needed\n */\n persistenceContext?: PersistenceContext;\n\n logger: LoggerService;\n config: Config;\n discovery: DiscoveryService;\n database: DatabaseService;\n scheduler: SchedulerService;\n auth: AuthService;\n urlReader: UrlReaderService;\n}\n\n/**\n * @public\n * @typeParam CheckType - Type of the check for the fact checker this builder returns\n * @typeParam CheckResultType - Type of the check result for the fact checker this builder returns\n *\n * A container for exported implementations related to TechInsights.\n * FactChecker is present if an optional FactCheckerFactory is included in the build stage.\n */\nexport type TechInsightsContext<\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n> = {\n factChecker?: FactChecker<CheckType, CheckResultType>;\n persistenceContext: PersistenceContext;\n factRetrieverEngine: FactRetrieverEngine;\n};\n\n/**\n * @public\n *\n * Constructs needed persistence context, fact retriever engine\n * and optionally fact checker implementations to be used in the tech insights module.\n *\n * @param options - Needed options to construct TechInsightsContext\n * @returns TechInsightsContext with persistence implementations and optionally an implementation of a FactChecker\n */\nexport const buildTechInsightsContext = async <\n CheckType extends TechInsightCheck,\n CheckResultType extends CheckResult,\n>(\n options: TechInsightsOptions<CheckType, CheckResultType>,\n): Promise<TechInsightsContext<CheckType, CheckResultType>> => {\n const {\n factRetrievers,\n factCheckerFactory,\n config,\n discovery,\n database,\n logger,\n scheduler,\n auth,\n urlReader,\n } = options;\n\n const buildFactRetrieverRegistry = (): FactRetrieverRegistry => {\n if (!options.factRetrieverRegistry) {\n if (!factRetrievers) {\n throw new Error(\n 'Failed to build FactRetrieverRegistry because no factRetrievers found',\n );\n }\n return new DefaultFactRetrieverRegistry(factRetrievers);\n }\n return options.factRetrieverRegistry;\n };\n\n const factRetrieverRegistry = buildFactRetrieverRegistry();\n\n const persistenceContext =\n options.persistenceContext ??\n (await initializePersistenceContext(database, {\n logger,\n }));\n\n const factRetrieverEngine = await DefaultFactRetrieverEngine.create({\n scheduler,\n repository: persistenceContext.techInsightsStore,\n factRetrieverRegistry,\n factRetrieverContext: {\n config,\n discovery,\n logger,\n auth,\n urlReader,\n },\n });\n\n await factRetrieverEngine.schedule();\n\n if (factCheckerFactory) {\n const factChecker = factCheckerFactory.construct(\n persistenceContext.techInsightsStore,\n );\n return {\n persistenceContext,\n factChecker,\n factRetrieverEngine,\n };\n }\n\n return {\n persistenceContext,\n factRetrieverEngine,\n };\n};\n"],"names":["DefaultFactRetrieverRegistry","persistenceContext","initializePersistenceContext","DefaultFactRetrieverEngine"],"mappings":";;;;;;AAkHa,MAAA,wBAAA,GAA2B,OAItC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A,MACA,mBAAA;AAAA,KACF,CAAA;AAAA,GACF;AAEA,EAAO,OAAA;AAAA,wBACLA,oBAAA;AAAA,IACA,mBAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage-community/plugin-tech-insights-backend",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "backend-plugin",
|
|
6
6
|
"pluginId": "tech-insights",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@backstage-community/plugin-tech-insights-common": "^0.2.21",
|
|
49
|
-
"@backstage-community/plugin-tech-insights-node": "^
|
|
49
|
+
"@backstage-community/plugin-tech-insights-node": "^2.0.0",
|
|
50
50
|
"@backstage/backend-defaults": "^0.5.2",
|
|
51
51
|
"@backstage/backend-plugin-api": "^1.0.1",
|
|
52
52
|
"@backstage/backend-tasks": "^0.6.1",
|