m8chaa commited on
Commit
8ff087a
·
verified ·
1 Parent(s): 338411c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -1000,12 +1000,15 @@ async def setup_listener():
1000
  users_ref = db.collection('users')
1001
  async for change in users_ref.on_snapshot():
1002
  # Handle changes
1003
- pass
 
1004
  except Exception as e:
1005
  print(f"Listener disconnected: {e}")
1006
  await asyncio.sleep(5) # Wait before reconnecting
1007
 
1008
- asyncio.run(setup_listener())
 
 
1009
 
1010
  # # Set up the Firebase listener
1011
  # users_watch = users_collection_ref.on_snapshot(on_snapshot)
 
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
  # # Set up the Firebase listener
1014
  # users_watch = users_collection_ref.on_snapshot(on_snapshot)