Spaces:
Paused
Paused
File size: 796 Bytes
1bc0412 4db7b7b 1bc0412 4db7b7b 1bc0412 4db7b7b 1bc0412 b56f564 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import requests
import time
import datetime
import os
LOCAL_PORT = os.environ.get("SERVER_PORT", "7860")
LOCAL_URL = f"http://127.0.0.1:{LOCAL_PORT}/health"
TARGETS = [LOCAL_URL]
def start_pinging():
print(f"[*] Keep-alive targets: {TARGETS}")
fail_count = 0
while True:
for url in TARGETS:
try:
r = requests.get(url, timeout=15)
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{now}] {url} -> {r.status_code}")
fail_count = 0
except Exception as e:
fail_count += 1
print(f"[!] Error: {url} -> {e}")
sleep_time = 180 if fail_count == 0 else 60
time.sleep(sleep_time)
if __name__ == "__main__":
start_pinging()
|