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()