Python-based time management application with UDP discovery, TCP protocol communication, time sync, and drift monitoring. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""전체 컨트롤러 시간 동기화 서비스"""
|
|
|
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
from datetime import datetime
|
|
|
|
from models.controller import Controller
|
|
from network.tcp_protocol import sync_time
|
|
|
|
|
|
def sync_all(
|
|
controllers: list[Controller],
|
|
max_workers: int = 8,
|
|
) -> list[tuple[Controller, bool, str]]:
|
|
"""선택된 컨트롤러에 일괄 시간 동기화.
|
|
|
|
Returns: [(Controller, 성공여부, 메시지), ...]
|
|
"""
|
|
targets = [c for c in controllers if c.selected]
|
|
if not targets:
|
|
return []
|
|
|
|
dt = datetime.now()
|
|
results: list[tuple[Controller, bool, str]] = []
|
|
|
|
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
future_map = {
|
|
executor.submit(sync_time, c.ip, c.port, dt): c
|
|
for c in targets
|
|
}
|
|
for future in as_completed(future_map):
|
|
ctrl = future_map[future]
|
|
try:
|
|
ok, msg = future.result()
|
|
except Exception as e:
|
|
ok, msg = False, str(e)
|
|
results.append((ctrl, ok, msg))
|
|
|
|
return results
|