Spaces:
Running
Running
File size: 972 Bytes
9726e3d 80f5fef 9726e3d 80f5fef 9726e3d 80f5fef 9726e3d 80f5fef 9726e3d 80f5fef 9726e3d 80f5fef 9726e3d 80f5fef 9726e3d | 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 31 32 | import requests
import time
import os
import logging
from threading import Timer
#logging.basicConfig(level="INFO")
log = logging.getLogger(__name__)
# Get config from environment variables
URL = os.getenv('MASTER_URL', 'http://localhost:8000/hc')
HOST_URL = os.getenv('SENDER_URL', 'http://my-sender-host.com')
INTERVAL = int(os.getenv('SENDER_INTERVAL', '43200')) # 12 hours
def send_timestamp():
try:
response = requests.get(URL, params={
'timestamp': time.time(),
'host_url': HOST_URL
})
log.info(f"Sent timestamp to {URL}: {response.status_code}")
except Exception as e:
log.info(f"Error sending timestamp to {URL}: {type(e).__name__}: {e}")
# Schedule next call
Timer(INTERVAL, send_timestamp).start()
log.info(f"Scheduled next timestamp send in {INTERVAL} seconds")
# Start the first call
log.info(f"Starting timestamp sender to {URL} every {INTERVAL} seconds")
send_timestamp() |