Spaces:
Running
Running
Update server.py
Browse files
server.py
CHANGED
|
@@ -10,6 +10,8 @@ import json
|
|
| 10 |
import asyncio
|
| 11 |
import subprocess
|
| 12 |
import tempfile
|
|
|
|
|
|
|
| 13 |
from pathlib import Path
|
| 14 |
from datetime import datetime
|
| 15 |
from dotenv import load_dotenv
|
|
@@ -407,7 +409,7 @@ async def scan_and_compress_videos():
|
|
| 407 |
|
| 408 |
@app.on_event("startup")
|
| 409 |
async def startup_event():
|
| 410 |
-
"""Schedule compression scan on server startup with 30s delay."""
|
| 411 |
print("\n" + "="*80)
|
| 412 |
print("STARTUP EVENT TRIGGERED")
|
| 413 |
print("="*80)
|
|
@@ -424,14 +426,16 @@ async def startup_event():
|
|
| 424 |
except Exception as e:
|
| 425 |
print(f"✗ Error checking ffmpeg: {e}")
|
| 426 |
|
| 427 |
-
# Schedule scan
|
| 428 |
-
|
| 429 |
print("\nWaiting 30 seconds before starting compression scan...")
|
| 430 |
-
|
| 431 |
print("Starting compression scan now...")
|
| 432 |
-
|
| 433 |
|
| 434 |
-
|
|
|
|
|
|
|
| 435 |
|
| 436 |
|
| 437 |
@app.get("/")
|
|
|
|
| 10 |
import asyncio
|
| 11 |
import subprocess
|
| 12 |
import tempfile
|
| 13 |
+
import threading
|
| 14 |
+
import time
|
| 15 |
from pathlib import Path
|
| 16 |
from datetime import datetime
|
| 17 |
from dotenv import load_dotenv
|
|
|
|
| 409 |
|
| 410 |
@app.on_event("startup")
|
| 411 |
async def startup_event():
|
| 412 |
+
"""Schedule compression scan on server startup with 30s delay using background thread."""
|
| 413 |
print("\n" + "="*80)
|
| 414 |
print("STARTUP EVENT TRIGGERED")
|
| 415 |
print("="*80)
|
|
|
|
| 426 |
except Exception as e:
|
| 427 |
print(f"✗ Error checking ffmpeg: {e}")
|
| 428 |
|
| 429 |
+
# Schedule scan in a background thread (more reliable for deployment)
|
| 430 |
+
def run_delayed_scan():
|
| 431 |
print("\nWaiting 30 seconds before starting compression scan...")
|
| 432 |
+
time.sleep(30)
|
| 433 |
print("Starting compression scan now...")
|
| 434 |
+
asyncio.run(scan_and_compress_videos())
|
| 435 |
|
| 436 |
+
scan_thread = threading.Thread(target=run_delayed_scan, daemon=True)
|
| 437 |
+
scan_thread.start()
|
| 438 |
+
print("✓ Background scan thread scheduled")
|
| 439 |
|
| 440 |
|
| 441 |
@app.get("/")
|