fix: dashboard integration, remove port 8081, countdown persistence
This commit is contained in:
+25
-14
@@ -1,15 +1,20 @@
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
from socketserver import ThreadingMixIn
|
||||
|
||||
from health import HealthServer, SyncSession
|
||||
from health import SyncSession
|
||||
|
||||
|
||||
class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
|
||||
daemon_threads = True
|
||||
|
||||
|
||||
class DashboardServer:
|
||||
def __init__(self, port: int = 8082, health: HealthServer = None, session: SyncSession = None):
|
||||
def __init__(self, port: int = 8082, session: SyncSession = None):
|
||||
self.port = port
|
||||
self.health = health
|
||||
self.session = session
|
||||
self.server = None
|
||||
self.thread = None
|
||||
@@ -19,11 +24,15 @@ class DashboardServer:
|
||||
self._event_count = 0
|
||||
self._backoff_min = 0
|
||||
self._config = {}
|
||||
self._last_sync = None
|
||||
self._last_duration = 0.0
|
||||
self._last_success = None
|
||||
self._last_latency_ms = 0
|
||||
self._base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
def start(self):
|
||||
handler = self._make_handler()
|
||||
self.server = HTTPServer(("0.0.0.0", self.port), handler)
|
||||
self.server = ThreadingHTTPServer(("0.0.0.0", self.port), handler)
|
||||
self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
|
||||
self.thread.start()
|
||||
|
||||
@@ -53,6 +62,13 @@ class DashboardServer:
|
||||
with self._lock:
|
||||
self._backoff_min = n
|
||||
|
||||
def set_last_sync(self, last_sync, duration: float, success: bool, latency_ms: int = 0):
|
||||
with self._lock:
|
||||
self._last_sync = last_sync
|
||||
self._last_duration = duration
|
||||
self._last_success = success
|
||||
self._last_latency_ms = latency_ms
|
||||
|
||||
def _get_status(self):
|
||||
with self._lock:
|
||||
syncing = self._syncing
|
||||
@@ -60,15 +76,10 @@ class DashboardServer:
|
||||
event_count = self._event_count
|
||||
backoff_min = self._backoff_min
|
||||
config = dict(self._config)
|
||||
|
||||
last_sync = None
|
||||
duration = 0.0
|
||||
last_success = None
|
||||
if self.health:
|
||||
with self.health.lock:
|
||||
last_sync = self.health.last_sync
|
||||
duration = self.health.last_sync_duration
|
||||
last_success = self.health.last_sync_success
|
||||
last_sync = self._last_sync
|
||||
duration = self._last_duration
|
||||
last_success = self._last_success
|
||||
latency_ms = self._last_latency_ms
|
||||
|
||||
status = "idle"
|
||||
if syncing:
|
||||
@@ -92,7 +103,7 @@ class DashboardServer:
|
||||
"status": status,
|
||||
"last_sync": last_sync.isoformat() if last_sync else None,
|
||||
"duration": duration,
|
||||
"ics_latency_ms": ics_latency,
|
||||
"ics_latency_ms": ics_latency if ics_latency else latency_ms,
|
||||
"event_count": event_count,
|
||||
"next_sync_in": next_sync_in,
|
||||
"session": session_data,
|
||||
|
||||
Reference in New Issue
Block a user