diff --git a/.changeset/strong-planes-return.md b/.changeset/strong-planes-return.md new file mode 100644 index 0000000000..5b5648528a --- /dev/null +++ b/.changeset/strong-planes-return.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-node': patch +--- + +Support for timeout in FactRetrieverRegistrationOptions diff --git a/plugins/tech-insights-backend/api-report.md b/plugins/tech-insights-backend/api-report.md index b7de961034..94ac35ad9f 100644 --- a/plugins/tech-insights-backend/api-report.md +++ b/plugins/tech-insights-backend/api-report.md @@ -5,6 +5,7 @@ ```ts import { CheckResult } from '@backstage/plugin-tech-insights-common'; import { Config } from '@backstage/config'; +import { Duration } from 'luxon'; import express from 'express'; import { FactChecker } from '@backstage/plugin-tech-insights-node'; import { FactCheckerFactory } from '@backstage/plugin-tech-insights-node'; @@ -12,6 +13,7 @@ import { FactLifecycle } from '@backstage/plugin-tech-insights-node'; import { FactRetriever } from '@backstage/plugin-tech-insights-node'; import { FactRetrieverRegistration } from '@backstage/plugin-tech-insights-node'; import { FactSchema } from '@backstage/plugin-tech-insights-node'; +import { HumanDuration } from '@backstage/backend-tasks'; import { Logger } from 'winston'; import { PluginDatabaseManager } from '@backstage/backend-common'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; @@ -57,6 +59,7 @@ export type FactRetrieverRegistrationOptions = { cadence: string; factRetriever: FactRetriever; lifecycle?: FactLifecycle; + timeout?: Duration | HumanDuration; }; // @public (undocumented) diff --git a/plugins/tech-insights-backend/package.json b/plugins/tech-insights-backend/package.json index 194959d163..e176a5d5f6 100644 --- a/plugins/tech-insights-backend/package.json +++ b/plugins/tech-insights-backend/package.json @@ -43,6 +43,7 @@ "@backstage/plugin-tech-insights-common": "^0.2.6", "@backstage/plugin-tech-insights-node": "^0.3.3", "@types/express": "^4.17.6", + "@types/luxon": "^3.0.0", "express": "^4.17.1", "express-promise-router": "^4.1.0", "knex": "^2.0.0", @@ -56,8 +57,8 @@ "devDependencies": { "@backstage/backend-test-utils": "^0.1.27", "@backstage/cli": "^0.18.1", - "@types/supertest": "^2.0.8", "@types/semver": "^7.3.8", + "@types/supertest": "^2.0.8", "supertest": "^6.1.3", "wait-for-expect": "^3.0.2" }, diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index de49888e1b..aaba29ecb1 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { HumanDuration } from '@backstage/backend-tasks'; import { FactLifecycle, FactRetriever, FactRetrieverRegistration, } from '@backstage/plugin-tech-insights-node'; +import { Duration } from 'luxon'; /** * @public @@ -25,22 +27,24 @@ import { * @param cadence - cron expression to indicate when the fact retriever should be triggered * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run + * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes * */ export type FactRetrieverRegistrationOptions = { cadence: string; factRetriever: FactRetriever; lifecycle?: FactLifecycle; + timeout?: Duration | HumanDuration; }; /** * @public * * A helper function to construct fact retriever registrations. - * - * @param cadence - cron expression to indicate when the fact retriever should be triggered + * @param cadence - Cron expression to indicate when the fact retriever should be triggered * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run + * @param timeout - Optional duration to determine how long the fact retriever should be allowed to run, defaults to 5 minutes * * * @remarks @@ -64,10 +68,11 @@ export type FactRetrieverRegistrationOptions = { export function createFactRetrieverRegistration( options: FactRetrieverRegistrationOptions, ): FactRetrieverRegistration { - const { cadence, factRetriever, lifecycle } = options; + const { cadence, factRetriever, lifecycle, timeout } = options; return { cadence, factRetriever, lifecycle, + timeout, }; } diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index 19645d604b..a57cf3ec4a 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -8,6 +8,7 @@ import { Config } from '@backstage/config'; import { DateTime } from 'luxon'; import { Duration } from 'luxon'; import { DurationLike } from 'luxon'; +import { HumanDuration } from '@backstage/backend-tasks'; import { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; @@ -72,7 +73,7 @@ export type FactRetrieverContext = { export type FactRetrieverRegistration = { factRetriever: FactRetriever; cadence?: string; - timeout?: Duration; + timeout?: Duration | HumanDuration; lifecycle?: FactLifecycle; }; diff --git a/plugins/tech-insights-node/package.json b/plugins/tech-insights-node/package.json index 0233fac050..355806bdfa 100644 --- a/plugins/tech-insights-node/package.json +++ b/plugins/tech-insights-node/package.json @@ -34,6 +34,7 @@ }, "dependencies": { "@backstage/backend-common": "^0.15.0", + "@backstage/backend-tasks": "^0.3.4", "@backstage/config": "^1.0.1", "@backstage/plugin-tech-insights-common": "^0.2.6", "@backstage/types": "^1.0.0", diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index cda238694f..41db302fd5 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -21,6 +21,7 @@ import { TokenManager, } from '@backstage/backend-common'; import { Logger } from 'winston'; +import { HumanDuration } from '@backstage/backend-tasks'; /** * A container for facts. The shape of the fact records needs to correspond to the FactSchema with same `ref` value. @@ -270,7 +271,7 @@ export type FactRetrieverRegistration = { * defaults to 5 minutes. * */ - timeout?: Duration; + timeout?: Duration | HumanDuration; /** * Fact lifecycle definition