adacam-odc: internet check before forwarder cycle (DNS probe, exponential backoff when offline)
This commit is contained in:
parent
4ca2a8f14d
commit
9903667c71
1 changed files with 20 additions and 0 deletions
|
|
@ -901,6 +901,17 @@ def forwarder_process_cycle() -> Tuple[int, int]:
|
|||
# =============================================================================
|
||||
|
||||
|
||||
|
||||
def is_internet_available(host: str = "8.8.8.8", port: int = 53, timeout: int = 3) -> bool:
|
||||
"""Quick internet connectivity check — DNS port probe, no HTTP overhead."""
|
||||
import socket
|
||||
try:
|
||||
socket.setdefaulttimeout(timeout)
|
||||
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def forwarder_thread_main():
|
||||
"""Main function for forwarder thread."""
|
||||
fwd_logger.info("╔════════════════════════════════════════════════════════════╗")
|
||||
|
|
@ -920,6 +931,15 @@ def forwarder_thread_main():
|
|||
|
||||
while not shutdown_event.is_set():
|
||||
try:
|
||||
if not is_internet_available():
|
||||
fwd_logger.debug("No internet connectivity — skipping cycle, will retry")
|
||||
for _ in range(min(backoff_seconds, max_backoff)):
|
||||
if shutdown_event.is_set():
|
||||
break
|
||||
time.sleep(1)
|
||||
backoff_seconds = min(backoff_seconds * 2, max_backoff)
|
||||
continue
|
||||
|
||||
det_sent, img_uploaded = forwarder_process_cycle()
|
||||
|
||||
if det_sent > 0 or img_uploaded > 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue