Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -989,11 +989,26 @@ async def notifications(request: Request):
|
|
| 989 |
except Exception as e:
|
| 990 |
raise HTTPException(status_code=500, detail=str(e))
|
| 991 |
|
| 992 |
-
# Set up the Firebase listener
|
| 993 |
-
users_watch = users_collection_ref.on_snapshot(on_snapshot)
|
| 994 |
|
| 995 |
-
|
| 996 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 997 |
# scheduler.add_job(update_watch_list, 'interval', hours=24)
|
| 998 |
# scheduler.start()
|
| 999 |
|
|
|
|
| 989 |
except Exception as e:
|
| 990 |
raise HTTPException(status_code=500, detail=str(e))
|
| 991 |
|
|
|
|
|
|
|
| 992 |
|
| 993 |
+
async def setup_listener():
|
| 994 |
+
while True:
|
| 995 |
+
try:
|
| 996 |
+
db = AsyncClient()
|
| 997 |
+
users_ref = db.collection('users')
|
| 998 |
+
async for change in users_ref.on_snapshot():
|
| 999 |
+
# Handle changes
|
| 1000 |
+
pass
|
| 1001 |
+
except Exception as e:
|
| 1002 |
+
print(f"Listener disconnected: {e}")
|
| 1003 |
+
await asyncio.sleep(5) # Wait before reconnecting
|
| 1004 |
+
|
| 1005 |
+
asyncio.run(setup_listener())
|
| 1006 |
+
|
| 1007 |
+
# # Set up the Firebase listener
|
| 1008 |
+
# users_watch = users_collection_ref.on_snapshot(on_snapshot)
|
| 1009 |
+
|
| 1010 |
+
# # Set up the scheduler to update watch list every 24 hours
|
| 1011 |
+
# scheduler = BackgroundScheduler()
|
| 1012 |
# scheduler.add_job(update_watch_list, 'interval', hours=24)
|
| 1013 |
# scheduler.start()
|
| 1014 |
|