Rename refresh methods, cleanup previous code
Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -72,13 +72,6 @@ class Connection implements EntityProviderConnection {
|
||||
removed: mutation.removed,
|
||||
});
|
||||
});
|
||||
} else if (mutation.type === 'refresh') {
|
||||
// await db.transaction(async tx => {
|
||||
// await db.refreshUnprocessedEntities(tx, {
|
||||
// match: mutation.match,
|
||||
// });
|
||||
// });
|
||||
console.log('wopoop');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,19 +242,8 @@ export class DefaultCatalogProcessingEngine implements CatalogProcessingEngine {
|
||||
|
||||
async refresh(options: EntityRefreshOptions) {
|
||||
await this.processingDatabase.transaction(async tx => {
|
||||
await this.processingDatabase.refreshUnprocessedEntities(tx, options);
|
||||
await this.processingDatabase.refresh(tx, options);
|
||||
});
|
||||
// await Promise.all(
|
||||
// this.entityProviders.map(async provider => {
|
||||
// try {
|
||||
// await provider.refresh?.(options);
|
||||
// } catch (e) {
|
||||
// throw new Error(
|
||||
// `Provider ${provider.getProviderName()} failed refresh, ${e}`,
|
||||
// );
|
||||
// }
|
||||
// }),
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +19,10 @@ import { ConflictError, NotFoundError } from '@backstage/errors';
|
||||
import { Knex } from 'knex';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { DbLocationsRow } from './database/tables';
|
||||
import { RefreshStateMatch } from './database/types';
|
||||
import { getEntityLocationRef } from './processing/util';
|
||||
import {
|
||||
EntityProvider,
|
||||
EntityProviderConnection,
|
||||
EntityRefreshOptions,
|
||||
LocationStore,
|
||||
} from './types';
|
||||
import { locationSpecToLocationEntity } from './util';
|
||||
@@ -137,22 +135,6 @@ export class DefaultLocationStore implements LocationStore, EntityProvider {
|
||||
});
|
||||
}
|
||||
|
||||
async refresh(_options: EntityRefreshOptions) {
|
||||
// const match: RefreshStateMatch = {};
|
||||
// // locationKey?: string;
|
||||
// // entityRef?: string;
|
||||
// if (options.entityRef) {
|
||||
// match.entityRef = options.entityRef;
|
||||
// }
|
||||
// if (options.locationRef) {
|
||||
// // TODO
|
||||
// }
|
||||
// await this.connection.applyMutation({
|
||||
// type: 'refresh',
|
||||
// match,
|
||||
// });
|
||||
}
|
||||
|
||||
private async locations(dbOrTx: Knex.Transaction | Knex = this.db) {
|
||||
const locations = await dbOrTx<DbLocationsRow>('locations').select();
|
||||
return (
|
||||
|
||||
@@ -14,11 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
Entity,
|
||||
LOCATION_ANNOTATION,
|
||||
stringifyEntityRef,
|
||||
} from '@backstage/catalog-model';
|
||||
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
|
||||
import { JsonObject } from '@backstage/config';
|
||||
import { ConflictError, NotFoundError } from '@backstage/errors';
|
||||
import { Knex } from 'knex';
|
||||
@@ -40,7 +36,7 @@ import {
|
||||
GetProcessableEntitiesResult,
|
||||
ProcessingDatabase,
|
||||
RefreshStateItem,
|
||||
RefreshUnprocessedEntitiesOptions,
|
||||
RefreshOptions,
|
||||
ReplaceUnprocessedEntitiesOptions,
|
||||
UpdateProcessedEntityOptions,
|
||||
} from './types';
|
||||
@@ -515,11 +511,7 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
|
||||
};
|
||||
}
|
||||
|
||||
// TODO(jhaals): Rename this to refreshEntity/refreshEntities?
|
||||
async refreshUnprocessedEntities(
|
||||
txOpaque: Transaction,
|
||||
options: RefreshUnprocessedEntitiesOptions,
|
||||
): Promise<void> {
|
||||
async refresh(txOpaque: Transaction, options: RefreshOptions): Promise<void> {
|
||||
const tx = txOpaque as Knex.Transaction;
|
||||
if ('entityRef' in options) {
|
||||
const { entityRef } = options;
|
||||
|
||||
@@ -79,19 +79,10 @@ export type ReplaceUnprocessedEntitiesOptions =
|
||||
type: 'delta';
|
||||
};
|
||||
|
||||
export type RefreshStateMatch = {
|
||||
locationKey?: string;
|
||||
entityRef?: string;
|
||||
parentOfEntityRef: string;
|
||||
export type RefreshOptions = {
|
||||
entityRef: string;
|
||||
};
|
||||
|
||||
export type RefreshUnprocessedEntitiesOptions =
|
||||
| {
|
||||
// match: RefreshStateMatch;
|
||||
entityRef: string;
|
||||
}
|
||||
| { locationRef: string };
|
||||
|
||||
export interface ProcessingDatabase {
|
||||
transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
|
||||
|
||||
@@ -121,8 +112,5 @@ export interface ProcessingDatabase {
|
||||
options: UpdateProcessedEntityErrorsOptions,
|
||||
): Promise<void>;
|
||||
|
||||
refreshUnprocessedEntities(
|
||||
txOpaque: Transaction,
|
||||
options: RefreshUnprocessedEntitiesOptions,
|
||||
): Promise<void>;
|
||||
refresh(txOpaque: Transaction, options: RefreshOptions): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
import { Entity, Location, LocationSpec } from '@backstage/catalog-model';
|
||||
import { RefreshStateMatch } from './database/types';
|
||||
import { DeferredEntity } from './processing/types';
|
||||
|
||||
export interface LocationService {
|
||||
@@ -41,12 +40,9 @@ export interface CatalogProcessingEngine {
|
||||
refresh(options: EntityRefreshOptions): Promise<void>;
|
||||
}
|
||||
|
||||
export type EntityRefreshOptions =
|
||||
| { entityRef: string } // example: component:default/backstage
|
||||
| { locationRef: string }; // example: url:https://github.com/backstage/backstage/blob/master/catalog-info.yaml
|
||||
export type EntityRefreshOptions = { entityRef: string };
|
||||
|
||||
export type EntityProviderMutation =
|
||||
| { type: 'refresh'; match: RefreshStateMatch } // TODO(jhaals): Should this really use a type from the db?
|
||||
| { type: 'full'; entities: DeferredEntity[] }
|
||||
| { type: 'delta'; added: DeferredEntity[]; removed: DeferredEntity[] };
|
||||
|
||||
@@ -57,5 +53,4 @@ export interface EntityProviderConnection {
|
||||
export interface EntityProvider {
|
||||
getProviderName(): string;
|
||||
connect(connection: EntityProviderConnection): Promise<void>;
|
||||
refresh?(options: EntityRefreshOptions): Promise<void>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user