LucaR84 commited on
Commit
80f5fef
·
verified ·
1 Parent(s): 0d721b5

Update sync_hc/__init__.py

Browse files
Files changed (1) hide show
  1. sync_hc/__init__.py +10 -5
sync_hc/__init__.py CHANGED
@@ -1,12 +1,17 @@
1
  import requests
2
  import time
3
  import os
 
4
  from threading import Timer
5
 
 
 
 
 
6
  # Get config from environment variables
7
  URL = os.getenv('MASTER_URL', 'http://localhost:8000/hc')
8
  HOST_URL = os.getenv('SENDER_URL', 'http://my-sender-host.com')
9
- INTERVAL = int(os.getenv('SENDER_INTERVAL', '5')) # seconds
10
 
11
  def send_timestamp():
12
  try:
@@ -14,14 +19,14 @@ def send_timestamp():
14
  'timestamp': time.time(),
15
  'host_url': HOST_URL
16
  })
17
- print(f"Sent timestamp to {URL}: {response.status_code}")
18
  except Exception as e:
19
- print(f"Error sending timestamp to {URL}: {type(e).__name__}: {e}")
20
 
21
  # Schedule next call
22
  Timer(INTERVAL, send_timestamp).start()
23
- print(f"Scheduled next timestamp send in {INTERVAL} seconds")
24
 
25
  # Start the first call
26
- print(f"Starting timestamp sender to {URL} every {INTERVAL} seconds")
27
  send_timestamp()
 
1
  import requests
2
  import time
3
  import os
4
+ import logging
5
  from threading import Timer
6
 
7
+ #logging.basicConfig(level="INFO")
8
+
9
+ log = logging.getLogger(__name__)
10
+
11
  # Get config from environment variables
12
  URL = os.getenv('MASTER_URL', 'http://localhost:8000/hc')
13
  HOST_URL = os.getenv('SENDER_URL', 'http://my-sender-host.com')
14
+ INTERVAL = int(os.getenv('SENDER_INTERVAL', '43200')) # 12 hours
15
 
16
  def send_timestamp():
17
  try:
 
19
  'timestamp': time.time(),
20
  'host_url': HOST_URL
21
  })
22
+ log.info(f"Sent timestamp to {URL}: {response.status_code}")
23
  except Exception as e:
24
+ log.info(f"Error sending timestamp to {URL}: {type(e).__name__}: {e}")
25
 
26
  # Schedule next call
27
  Timer(INTERVAL, send_timestamp).start()
28
+ log.info(f"Scheduled next timestamp send in {INTERVAL} seconds")
29
 
30
  # Start the first call
31
+ log.info(f"Starting timestamp sender to {URL} every {INTERVAL} seconds")
32
  send_timestamp()