Refactor event to a type

Signed-off-by: sblausten <sam@roadie.io>
This commit is contained in:
sblausten
2023-04-04 17:42:14 +02:00
parent fb8c2971ae
commit 1f6ef31467
4 changed files with 35 additions and 5 deletions
+1
View File
@@ -40,6 +40,7 @@
"@backstage/plugin-azure-sites-backend": "workspace:^",
"@backstage/plugin-badges-backend": "workspace:^",
"@backstage/plugin-catalog-backend": "workspace:^",
"@backstage/plugin-catalog-backend-module-github": "workspace:^",
"@backstage/plugin-catalog-node": "workspace:^",
"@backstage/plugin-code-coverage-backend": "workspace:^",
"@backstage/plugin-entity-feedback-backend": "workspace:^",
@@ -311,3 +311,29 @@ export type Cursor = {
*/
totalItems?: number;
};
/**
* The details of the conflicting entity.
*/
export type CatalogConflictEventPayload = {
/**
* The new conflicting entity
*/
entity: Entity;
/**
* The new conflicting entity's ref
*/
entityRef: string;
/**
* The location key of this new conflicting entity
*/
newLocationKey: string;
/**
* The location key of the entity already in the catalog that shares the same name and namespace as this entity
*/
existingLocationKey: string;
/**
* The datetime that the conflict was processed at
*/
lastConflictAt: string;
};
@@ -44,9 +44,10 @@ import { checkLocationKeyConflict } from './operations/refreshState/checkLocatio
import { insertUnprocessedEntity } from './operations/refreshState/insertUnprocessedEntity';
import { updateUnprocessedEntity } from './operations/refreshState/updateUnprocessedEntity';
import { generateStableHash } from './util';
import { EventBroker } from '@backstage/plugin-events-node';
import { EventBroker, EventParams } from '@backstage/plugin-events-node';
import { DateTime } from 'luxon';
import { CATALOG_CONFLICTS_TOPIC } from '../constants';
import { CatalogConflictEventPayload } from '../catalog/types';
// The number of items that are sent per batch to the database layer, when
// doing .batchInsert calls to knex. This needs to be low enough to not cause
@@ -360,8 +361,8 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
this.options.logger.warn(
`Detected conflicting entityRef ${entityRef} already referenced by ${conflictingKey} and now also ${locationKey}`,
);
if (this.options.eventBroker) {
await this.options.eventBroker?.publish({
if (this.options.eventBroker && locationKey) {
const eventParams: EventParams<CatalogConflictEventPayload> = {
topic: CATALOG_CONFLICTS_TOPIC,
eventPayload: {
entity,
@@ -370,7 +371,8 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
existingLocationKey: conflictingKey,
lastConflictAt: DateTime.now().toISO(),
},
});
};
await this.options.eventBroker?.publish(eventParams);
}
}
}
+2 -1
View File
@@ -5142,7 +5142,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-catalog-backend-module-github@workspace:plugins/catalog-backend-module-github":
"@backstage/plugin-catalog-backend-module-github@workspace:^, @backstage/plugin-catalog-backend-module-github@workspace:plugins/catalog-backend-module-github":
version: 0.0.0-use.local
resolution: "@backstage/plugin-catalog-backend-module-github@workspace:plugins/catalog-backend-module-github"
dependencies:
@@ -23482,6 +23482,7 @@ __metadata:
"@backstage/plugin-azure-sites-backend": "workspace:^"
"@backstage/plugin-badges-backend": "workspace:^"
"@backstage/plugin-catalog-backend": "workspace:^"
"@backstage/plugin-catalog-backend-module-github": "workspace:^"
"@backstage/plugin-catalog-node": "workspace:^"
"@backstage/plugin-code-coverage-backend": "workspace:^"
"@backstage/plugin-entity-feedback-backend": "workspace:^"