Merge pull request #9994 from backstage/freben/remove-stuff-in-catalog-backend

remove deprecations in catalog-backend
This commit is contained in:
Fredrik Adelöw
2022-03-04 14:46:53 +01:00
committed by GitHub
10 changed files with 17 additions and 150 deletions
+10
View File
@@ -0,0 +1,10 @@
---
'@backstage/plugin-catalog-backend': patch
---
**BREAKING**:
- Removed the previously deprecated `runPeriodically` export. Please use the `@backstage/backend-tasks` package instead, or copy [the actual implementation](https://github.com/backstage/backstage/blob/02875d4d56708c60f86f6b0a5b3da82e24988354/plugins/catalog-backend/src/util/runPeriodically.ts#L29) into your own code if you explicitly do not want coordination of task runs across your worker nodes.
- Removed the previously deprecated `CatalogProcessorLocationResult.optional` field. Please set the corresponding `LocationSpec.presence` field to `'optional'` instead.
- Related to the previous point, the `processingResult.location` function no longer has a second boolean `optional` argument. Please set the corresponding `LocationSpec.presence` field to `'optional'` instead.
- Removed the previously deprecated `StaticLocationProcessor`. It has not been in use for some time; its functionality is covered by `ConfigLocationEntityProvider` instead.
+2 -22
View File
@@ -333,7 +333,6 @@ export type CatalogProcessorErrorResult = {
export type CatalogProcessorLocationResult = {
type: 'location';
location: LocationSpec;
optional?: boolean;
};
// @public
@@ -812,7 +811,7 @@ function inputError(
// @public @deprecated (undocumented)
function location_2(
newLocation: LocationSpec,
optional?: boolean,
_optional?: boolean,
): CatalogProcessorResult;
// @public (undocumented)
@@ -1007,10 +1006,7 @@ export const processingResult: Readonly<{
atLocation: LocationSpec,
message: string,
) => CatalogProcessorResult;
readonly location: (
newLocation: LocationSpec,
optional?: boolean | undefined,
) => CatalogProcessorResult;
readonly location: (newLocation: LocationSpec) => CatalogProcessorResult;
readonly entity: (
atLocation: LocationSpec,
newEntity: Entity,
@@ -1074,22 +1070,6 @@ export interface RouterOptions {
refreshService?: RefreshService;
}
// @public @deprecated
export function runPeriodically(fn: () => any, delayMs: number): () => void;
// @public @deprecated (undocumented)
export class StaticLocationProcessor implements StaticLocationProcessor {
constructor(staticLocations: LocationSpec[]);
// (undocumented)
static fromConfig(config: Config): StaticLocationProcessor;
// (undocumented)
readLocation(
location: LocationSpec,
_optional: boolean,
emit: CatalogProcessorEmit,
): Promise<boolean>;
}
// @public (undocumented)
export class UrlReaderProcessor implements CatalogProcessor {
constructor(options: { reader: UrlReader; logger: Logger_2 });
@@ -68,9 +68,9 @@ export function generalError(
*/
export function location(
newLocation: LocationSpec,
optional?: boolean,
_optional?: boolean,
): CatalogProcessorResult {
return { type: 'location', location: newLocation, optional };
return { type: 'location', location: newLocation };
}
/**
@@ -54,11 +54,8 @@ export const processingResult = Object.freeze({
return { type: 'error', location: atLocation, error: new Error(message) };
},
location(
newLocation: LocationSpec,
optional?: boolean,
): CatalogProcessorResult {
return { type: 'location', location: newLocation, optional };
location(newLocation: LocationSpec): CatalogProcessorResult {
return { type: 'location', location: newLocation };
},
entity(atLocation: LocationSpec, newEntity: Entity): CatalogProcessorResult {
@@ -147,8 +147,6 @@ export type CatalogProcessorEmit = (generated: CatalogProcessorResult) => void;
export type CatalogProcessorLocationResult = {
type: 'location';
location: LocationSpec;
/** @deprecated Set `location.presence = 'optional'` instead */
optional?: boolean;
};
/** @public */
@@ -1,59 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Config } from '@backstage/config';
import {
processingResult,
CatalogProcessorEmit,
LocationSpec,
} from '../../api';
/**
* @deprecated no longer in use, replaced by the ConfigLocationEntityProvider.
* @public
*/
export class StaticLocationProcessor implements StaticLocationProcessor {
static fromConfig(config: Config): StaticLocationProcessor {
const locations: LocationSpec[] = [];
const lConfigs = config.getOptionalConfigArray('catalog.locations') ?? [];
for (const lConfig of lConfigs) {
const type = lConfig.getString('type');
const target = lConfig.getString('target');
locations.push({ type, target });
}
return new StaticLocationProcessor(locations);
}
constructor(private readonly staticLocations: LocationSpec[]) {}
async readLocation(
location: LocationSpec,
_optional: boolean,
emit: CatalogProcessorEmit,
): Promise<boolean> {
if (location.type !== 'bootstrap') {
return false;
}
for (const staticLocation of this.staticLocations) {
emit(processingResult.location(staticLocation));
}
return true;
}
}
@@ -28,6 +28,5 @@ export type {
PlaceholderResolverRead,
PlaceholderResolverResolveUrl,
} from './PlaceholderProcessor';
export { StaticLocationProcessor } from './StaticLocationProcessor';
export { UrlReaderProcessor } from './UrlReaderProcessor';
export { parseEntityYaml } from '../util/parse';
@@ -106,9 +106,8 @@ export class ProcessorOutputCollector {
this.deferredEntities.push({ entity, locationKey: location });
} else if (i.type === 'location') {
const presence = i.optional ? 'optional' : 'required';
const entity = locationSpecToLocationEntity(
{ presence, ...i.location },
i.location,
this.parentEntity,
);
const locationKey = getEntityLocationRef(entity);
@@ -14,5 +14,4 @@
* limitations under the License.
*/
export * from './runPeriodically';
export * from './RecursivePartial';
@@ -1,56 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Runs a function repeatedly, with a fixed wait between invocations.
*
* Supports async functions, and silently ignores exceptions and rejections.
*
* @param fn - The function to run. May return a Promise.
* @param delayMs - The delay between a completed function invocation and the
* next.
* @returns A function that, when called, stops the invocation loop.
* @deprecated use \@backstage/backend-tasks package instead.
* @public
*/
export function runPeriodically(fn: () => any, delayMs: number): () => void {
let cancel: () => void;
let cancelled = false;
const cancellationPromise = new Promise<void>(resolve => {
cancel = () => {
resolve();
cancelled = true;
};
});
const startRefresh = async () => {
while (!cancelled) {
try {
await fn();
} catch {
// ignore intentionally
}
await Promise.race([
new Promise(resolve => setTimeout(resolve, delayMs)),
cancellationPromise,
]);
}
};
startRefresh();
return cancel!;
}