mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-03-15 20:34:31 +00:00
Bulk convert comments above classes/functions/methods into proper docstrings
This commit is contained in:
@@ -10,12 +10,13 @@ from core.constants import SOFTWARE_VERSION
|
||||
from core.prometheus_metrics_handler import memory_use_gauge, spots_gauge, alerts_gauge
|
||||
|
||||
|
||||
# Provides a timed update of the application's status data.
|
||||
class StatusReporter:
|
||||
"""Provides a timed update of the application's status data."""
|
||||
|
||||
# Constructor
|
||||
def __init__(self, status_data, run_interval, web_server, cleanup_timer, spots, spot_providers, alerts,
|
||||
alert_providers):
|
||||
"""Constructor"""
|
||||
|
||||
self.status_data = status_data
|
||||
self.run_interval = run_interval
|
||||
self.web_server = web_server
|
||||
@@ -30,24 +31,28 @@ class StatusReporter:
|
||||
self.status_data["software-version"] = SOFTWARE_VERSION
|
||||
self.status_data["server-owner-callsign"] = SERVER_OWNER_CALLSIGN
|
||||
|
||||
# Start the reporter thread
|
||||
def start(self):
|
||||
"""Start the reporter thread"""
|
||||
|
||||
self._thread = Thread(target=self._run, daemon=True)
|
||||
self._thread.start()
|
||||
|
||||
# Stop any threads and prepare for application shutdown
|
||||
def stop(self):
|
||||
"""Stop any threads and prepare for application shutdown"""
|
||||
|
||||
self._stop_event.set()
|
||||
|
||||
# Thread entry point: report immediately on startup, then on each interval until stopped
|
||||
def _run(self):
|
||||
"""Thread entry point: report immediately on startup, then on each interval until stopped"""
|
||||
|
||||
while True:
|
||||
self._report()
|
||||
if self._stop_event.wait(timeout=self.run_interval):
|
||||
break
|
||||
|
||||
# Write status information
|
||||
def _report(self):
|
||||
"""Write status information"""
|
||||
|
||||
self.status_data["uptime"] = (datetime.now(pytz.UTC) - self.startup_time).total_seconds()
|
||||
self.status_data["mem_use_mb"] = round(psutil.Process(os.getpid()).memory_info().rss / (1024 * 1024), 3)
|
||||
self.status_data["num_spots"] = len(self.spots)
|
||||
@@ -57,7 +62,8 @@ class StatusReporter:
|
||||
"last_updated": p.last_update_time.replace(
|
||||
tzinfo=pytz.UTC).timestamp() if p.last_update_time.year > 2000 else 0,
|
||||
"last_spot": p.last_spot_time.replace(
|
||||
tzinfo=pytz.UTC).timestamp() if p.last_spot_time.year > 2000 else 0}, self.spot_providers))
|
||||
tzinfo=pytz.UTC).timestamp() if p.last_spot_time.year > 2000 else 0},
|
||||
self.spot_providers))
|
||||
self.status_data["alert_providers"] = list(
|
||||
map(lambda p: {"name": p.name, "enabled": p.enabled, "status": p.status,
|
||||
"last_updated": p.last_update_time.replace(
|
||||
@@ -81,4 +87,4 @@ class StatusReporter:
|
||||
# Update Prometheus metrics
|
||||
memory_use_gauge.set(psutil.Process(os.getpid()).memory_info().rss * 1024)
|
||||
spots_gauge.set(len(self.spots))
|
||||
alerts_gauge.set(len(self.alerts))
|
||||
alerts_gauge.set(len(self.alerts))
|
||||
|
||||
Reference in New Issue
Block a user