Spaces:
Running
Running
Making sure the server keeps running
Browse files
main.py
CHANGED
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from users.routes import router as users_router
|
@@ -36,6 +41,27 @@ def read_root():
|
|
36 |
def health_check():
|
37 |
return {"status": "ok"}
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
if __name__ == "__main__":
|
40 |
import uvicorn
|
41 |
uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
|
|
|
1 |
+
import schedule
|
2 |
+
import time
|
3 |
+
import requests
|
4 |
+
import threading
|
5 |
+
import asyncio
|
6 |
from fastapi import FastAPI
|
7 |
from fastapi.middleware.cors import CORSMiddleware
|
8 |
from users.routes import router as users_router
|
|
|
41 |
def health_check():
|
42 |
return {"status": "ok"}
|
43 |
|
44 |
+
|
45 |
+
def ping_server():
|
46 |
+
try:
|
47 |
+
print("Pinging server")
|
48 |
+
response = requests.get("https://testys-snapfeast-ai.hf.space")
|
49 |
+
except requests.exceptions.RequestException as e:
|
50 |
+
print("Server is down")
|
51 |
+
|
52 |
+
schedule.every(10).minutes.do(ping_server)
|
53 |
+
|
54 |
+
|
55 |
+
def run_schedule():
|
56 |
+
while True:
|
57 |
+
schedule.run_pending()
|
58 |
+
time.sleep(1)
|
59 |
+
|
60 |
+
|
61 |
+
thread = threading.Thread(target=run_schedule)
|
62 |
+
thread.daemon = True
|
63 |
+
thread.start()
|
64 |
+
|
65 |
if __name__ == "__main__":
|
66 |
import uvicorn
|
67 |
uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
|