Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -993,25 +993,10 @@ async def notifications(request: Request):
|
|
| 993 |
raise HTTPException(status_code=500, detail=str(e))
|
| 994 |
|
| 995 |
|
| 996 |
-
async def setup_listener():
|
| 997 |
-
while True:
|
| 998 |
-
try:
|
| 999 |
-
db = AsyncClient()
|
| 1000 |
-
users_ref = db.collection('users')
|
| 1001 |
-
async for change in users_ref.on_snapshot():
|
| 1002 |
-
# Handle changes
|
| 1003 |
-
print(f"Change detected: {change}")
|
| 1004 |
-
await asyncio.sleep(1) # Small delay to prevent tight loop
|
| 1005 |
-
except Exception as e:
|
| 1006 |
-
print(f"Listener disconnected: {e}")
|
| 1007 |
-
await asyncio.sleep(5) # Wait before reconnecting
|
| 1008 |
|
| 1009 |
-
@app.on_event("startup")
|
| 1010 |
-
async def startup_event():
|
| 1011 |
-
asyncio.create_task(setup_listener())
|
| 1012 |
|
| 1013 |
-
#
|
| 1014 |
-
|
| 1015 |
|
| 1016 |
# # Set up the scheduler to update watch list every 24 hours
|
| 1017 |
# scheduler = BackgroundScheduler()
|
|
|
|
| 993 |
raise HTTPException(status_code=500, detail=str(e))
|
| 994 |
|
| 995 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 996 |
|
|
|
|
|
|
|
|
|
|
| 997 |
|
| 998 |
+
# Set up the Firebase listener
|
| 999 |
+
users_watch = users_collection_ref.on_snapshot(on_snapshot)
|
| 1000 |
|
| 1001 |
# # Set up the scheduler to update watch list every 24 hours
|
| 1002 |
# scheduler = BackgroundScheduler()
|