Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1003,28 +1003,28 @@ users_watch = users_collection_ref.on_snapshot(on_snapshot)
|
|
| 1003 |
# scheduler.add_job(update_watch_list, 'interval', hours=24)
|
| 1004 |
# scheduler.start()
|
| 1005 |
|
| 1006 |
-
#
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
#
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
| 1016 |
|
| 1017 |
-
#
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
#
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
#
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
|
| 1028 |
-
#
|
| 1029 |
-
|
| 1030 |
-
|
|
|
|
| 1003 |
# scheduler.add_job(update_watch_list, 'interval', hours=24)
|
| 1004 |
# scheduler.start()
|
| 1005 |
|
| 1006 |
+
# Startup event to initialize the watch list
|
| 1007 |
+
@app.on_event("startup")
|
| 1008 |
+
async def startup_event():
|
| 1009 |
+
global gDrive_watch_list
|
| 1010 |
+
# Fetch all users and initialize the watch list
|
| 1011 |
+
users = users_collection_ref.get()
|
| 1012 |
+
for user in users:
|
| 1013 |
+
user_data = user.to_dict()
|
| 1014 |
+
if 'gDrive_metadata' in user_data and 'uploaded' in user_data['gDrive_metadata']:
|
| 1015 |
+
gDrive_watch_list[user.id] = user_data['gDrive_metadata']['uploaded']
|
| 1016 |
|
| 1017 |
+
# Initial update of watch list channels
|
| 1018 |
+
update_watch_list()
|
| 1019 |
+
|
| 1020 |
+
# Shutdown event to clean up resources
|
| 1021 |
+
@app.on_event("shutdown")
|
| 1022 |
+
async def shutdown_event():
|
| 1023 |
+
global watch_list_channels
|
| 1024 |
+
# Close all channels
|
| 1025 |
+
for channel_id, channel_info in watch_list_channels.items():
|
| 1026 |
+
close_channel(channel_id, channel_info['resourceId'])
|
| 1027 |
|
| 1028 |
+
# Stop the Firebase listener and the scheduler
|
| 1029 |
+
users_watch.unsubscribe()
|
| 1030 |
+
scheduler.shutdown()
|