fix: recover bgp anomaly and incident generation
This commit is contained in:
@@ -293,6 +293,12 @@ async def create_bgp_anomalies_for_batch(
|
||||
)
|
||||
)
|
||||
existing_keys = {row[0] for row in existing_result.fetchall()}
|
||||
existing_anomalies: list[BGPAnomaly] = []
|
||||
if existing_keys:
|
||||
existing_anomaly_result = await db.execute(
|
||||
select(BGPAnomaly).where(BGPAnomaly.entity_key.in_(sorted(existing_keys)))
|
||||
)
|
||||
existing_anomalies = existing_anomaly_result.scalars().all()
|
||||
|
||||
created = 0
|
||||
created_anomalies: list[BGPAnomaly] = []
|
||||
@@ -305,11 +311,13 @@ async def create_bgp_anomalies_for_batch(
|
||||
|
||||
if created:
|
||||
await db.commit()
|
||||
incident_seed_anomalies = [*created_anomalies, *existing_anomalies]
|
||||
if incident_seed_anomalies:
|
||||
await create_bgp_incidents_for_anomalies(
|
||||
db,
|
||||
source=source,
|
||||
snapshot_id=snapshot_id,
|
||||
task_id=task_id,
|
||||
anomalies=created_anomalies,
|
||||
anomalies=incident_seed_anomalies,
|
||||
)
|
||||
return created
|
||||
|
||||
Reference in New Issue
Block a user