import requests import time import os import logging from threading import Timer # 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 }) logging.info(f"Sent timestamp to {URL}: {response.status_code}") except Exception as e: logging.info(f"Error sending timestamp to {URL}: {type(e).__name__}: {e}") # Schedule next call Timer(INTERVAL, send_timestamp).start() logging.info(f"Scheduled next timestamp send in {INTERVAL} seconds") # Start the first call logging.info(f"Starting timestamp sender to {URL} every {INTERVAL} seconds") send_timestamp()