Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -127,29 +127,40 @@ def home():
|
|
| 127 |
return jsonify({"status": "running", "service": "HF Proxy"})
|
| 128 |
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
def keep_alive_worker():
|
|
|
|
|
|
|
| 137 |
while True:
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
time.sleep(PING_INTERVAL)
|
| 146 |
|
| 147 |
|
| 148 |
def start_background_thread():
|
| 149 |
-
thread = threading.Thread(
|
| 150 |
-
|
| 151 |
-
|
|
|
|
| 152 |
|
|
|
|
| 153 |
|
| 154 |
# =========================
|
| 155 |
# MAIN
|
|
|
|
| 127 |
return jsonify({"status": "running", "service": "HF Proxy"})
|
| 128 |
|
| 129 |
|
| 130 |
+
import requests
|
| 131 |
+
import threading
|
| 132 |
+
import time
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
PING_INTERVAL = 86400 # 24 hours
|
| 136 |
|
| 137 |
|
| 138 |
def keep_alive_worker():
|
| 139 |
+
url = "https://techbitforge-server.hf.space/"
|
| 140 |
+
|
| 141 |
while True:
|
| 142 |
+
try:
|
| 143 |
+
response = requests.get(url, timeout=120)
|
| 144 |
+
|
| 145 |
+
if response.status_code == 200:
|
| 146 |
+
print("Success: server is alive")
|
| 147 |
+
else:
|
| 148 |
+
print(f"Server returned status code: {response.status_code}")
|
| 149 |
+
|
| 150 |
+
except requests.RequestException as e:
|
| 151 |
+
print(f"Ping failed: {e}")
|
| 152 |
+
|
| 153 |
+
# Wait 24 hours before the next ping
|
| 154 |
time.sleep(PING_INTERVAL)
|
| 155 |
|
| 156 |
|
| 157 |
def start_background_thread():
|
| 158 |
+
thread = threading.Thread(
|
| 159 |
+
target=keep_alive_worker,
|
| 160 |
+
daemon=True
|
| 161 |
+
)
|
| 162 |
|
| 163 |
+
thread.start()
|
| 164 |
|
| 165 |
# =========================
|
| 166 |
# MAIN
|