Spaces:
Running
Running
File size: 1,999 Bytes
f9598ce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#!/usr/bin/env python3
"""
Script to reset alert notification status for testing
This clears the last_notified_at timestamp so alerts will trigger again
"""
import asyncio
import sys
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
from app.database import connect_db, disconnect_db, get_db
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
async def reset_alert_notifications():
"""Reset all alerts' last_notified_at to allow re-triggering"""
try:
# Connect to database
await connect_db()
db = await get_db()
# Reset all active alerts
result = await db.search_alerts.update_many(
{"is_active": True},
{"$set": {"last_notified_at": None}}
)
logger.info(f"✅ Reset {result.modified_count} alert(s)")
# Show active alerts
alerts = await db.search_alerts.find({"is_active": True}).to_list(length=None)
if alerts:
logger.info(f"\n{'='*60}")
logger.info(f"Active Alerts (Ready to Trigger Again):")
logger.info(f"{'='*60}")
for alert in alerts:
logger.info(f" Alert ID: {alert.get('_id')}")
logger.info(f" User: {alert.get('user_id')}")
logger.info(f" Query: {alert.get('user_query')}")
logger.info(f" Location: {alert.get('search_params', {}).get('location', 'Any')}")
logger.info(f" Last Notified: {alert.get('last_notified_at', 'Never')}")
logger.info(f" {'-'*60}")
logger.info(f"{'='*60}\n")
except Exception as e:
logger.error(f"Failed to reset alerts: {e}")
raise
finally:
await disconnect_db()
if __name__ == "__main__":
logger.info("Resetting alert notifications for testing...")
asyncio.run(reset_alert_notifications())
|