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