From 6a0a4ecbfd17d7e4dda30b1f46f0339e2f1e95e0 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Wed, 22 Jun 2022 00:25:32 +0200 Subject: [PATCH] Add refreshByRefreshKey to refresh service Signed-off-by: Kiss Miklos --- plugins/catalog-backend/src/api/processingResult.ts | 2 +- .../src/service/AuthorizedRefreshService.ts | 9 ++++++++- .../src/service/DefaultRefreshService.ts | 11 ++++++++++- plugins/catalog-backend/src/service/types.ts | 4 ++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/catalog-backend/src/api/processingResult.ts b/plugins/catalog-backend/src/api/processingResult.ts index fdc8280ed0..3f05b30acf 100644 --- a/plugins/catalog-backend/src/api/processingResult.ts +++ b/plugins/catalog-backend/src/api/processingResult.ts @@ -66,7 +66,7 @@ export const processingResult = Object.freeze({ return { type: 'relation', relation: spec }; }, - refresh(entity, key) { + refresh(entity: Entity, key: String) { return { type: 'refresh', entity, key }; }, } as const); diff --git a/plugins/catalog-backend/src/service/AuthorizedRefreshService.ts b/plugins/catalog-backend/src/service/AuthorizedRefreshService.ts index 8634fbf86d..2e48b3d8b6 100644 --- a/plugins/catalog-backend/src/service/AuthorizedRefreshService.ts +++ b/plugins/catalog-backend/src/service/AuthorizedRefreshService.ts @@ -20,7 +20,11 @@ import { AuthorizeResult, PermissionEvaluator, } from '@backstage/plugin-permission-common'; -import { RefreshOptions, RefreshService } from './types'; +import { + RefreshByRefreshKeysOptions, + RefreshOptions, + RefreshService, +} from './types'; export class AuthorizedRefreshService implements RefreshService { constructor( @@ -45,4 +49,7 @@ export class AuthorizedRefreshService implements RefreshService { } await this.service.refresh(options); } + async refreshByRefreshKey(options: RefreshByRefreshKeysOptions) { + await this.service.refreshByRefreshKey(options); + } } diff --git a/plugins/catalog-backend/src/service/DefaultRefreshService.ts b/plugins/catalog-backend/src/service/DefaultRefreshService.ts index 3b982a0e46..d0c2742d97 100644 --- a/plugins/catalog-backend/src/service/DefaultRefreshService.ts +++ b/plugins/catalog-backend/src/service/DefaultRefreshService.ts @@ -15,7 +15,11 @@ */ import { DefaultProcessingDatabase } from '../database/DefaultProcessingDatabase'; -import { RefreshOptions, RefreshService } from './types'; +import { + RefreshByRefreshKeysOptions, + RefreshOptions, + RefreshService, +} from './types'; export class DefaultRefreshService implements RefreshService { private database: DefaultProcessingDatabase; @@ -45,4 +49,9 @@ export class DefaultRefreshService implements RefreshService { }); }); } + async refreshByRefreshKey(options: RefreshByRefreshKeysOptions) { + await this.database.transaction(async tx => { + await this.database.refreshByRefreshKey(tx, options); + }); + } } diff --git a/plugins/catalog-backend/src/service/types.ts b/plugins/catalog-backend/src/service/types.ts index f6cfa2e783..cb4debc41d 100644 --- a/plugins/catalog-backend/src/service/types.ts +++ b/plugins/catalog-backend/src/service/types.ts @@ -61,6 +61,9 @@ export type RefreshOptions = { authorizationToken?: string; }; +export type RefreshByRefreshKeysOptions = { + key: string; +}; /** * A service that manages refreshes of entities in the catalog. * @@ -71,6 +74,7 @@ export interface RefreshService { * Request a refresh of entities in the catalog. */ refresh(options: RefreshOptions): Promise; + refreshByRefreshKey(options: RefreshByRefreshKeysOptions): Promise; } /**