| 1 | from loguru import logger |
| 2 | from sqlalchemy.ext.asyncio import AsyncSession |
| 3 | from sqlalchemy.future import select |
| 4 | |
| 5 | from app.integrations.monitoring_alert.models.monitoring_alert import MonitoringAlerts |
| 6 | |
| 7 | |
| 8 | async def remove_alert_id(alert_id: str, session: AsyncSession) -> None: |
| 9 | """ |
| 10 | Remove the alert with the given alert_id from the database. |
| 11 | |
| 12 | Args: |
| 13 | alert_id (str): The alert_id. |
| 14 | session (AsyncSession): The database session. |
| 15 | """ |
| 16 | logger.info(f"Removing alert with alert_id: {alert_id}") |
| 17 | |
| 18 | alert = await session.execute( |
| 19 | select(MonitoringAlerts).where(MonitoringAlerts.alert_id == alert_id), |
| 20 | ) |
| 21 | alert = alert.scalars().first() |
| 22 | |
| 23 | if not alert: |
| 24 | logger.error(f"Alert with alert_id: {alert_id} not found") |
| 25 | |
| 26 | await session.delete(alert) |
| 27 | await session.commit() |
| 28 | logger.info(f"Alert with alert_id: {alert_id} removed") |
| 29 | return None |