Techbitforge commited on
Commit
8dc65ba
·
verified ·
1 Parent(s): 5f3209c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -127,29 +127,40 @@ def home():
127
  return jsonify({"status": "running", "service": "HF Proxy"})
128
 
129
 
130
- # =========================
131
- # KEEP ALIVE PINGER
132
- # =========================
133
- HEADERS = {"User-Agent": "HF-Proxy-KeepAliveBot"}
 
 
134
 
135
 
136
  def keep_alive_worker():
 
 
137
  while True:
138
- logger.info("Pinging HF servers...")
139
- for url in HF_SERVERS + Server:
140
- try:
141
- r = requests.get(url, headers=HEADERS, timeout=8)
142
- logger.info(f"{url} → {r.status_code}")
143
- except Exception as e:
144
- logger.warning(f"{url} → ERROR: {e}")
 
 
 
 
 
145
  time.sleep(PING_INTERVAL)
146
 
147
 
148
  def start_background_thread():
149
- thread = threading.Thread(target=keep_alive_worker, daemon=True)
150
- thread.start()
151
- logger.info("Background keep-alive thread started")
 
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