mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-21 06:47:42 +00:00
Autogenerated type safety parameterisation of all methods
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime
|
||||
@@ -21,11 +23,11 @@ logger = logging.getLogger(__name__)
|
||||
class StatusReporter:
|
||||
"""Provides a timed update of the application's status data."""
|
||||
|
||||
def __init__(self, run_interval):
|
||||
def __init__(self, run_interval: float) -> None:
|
||||
"""Constructor"""
|
||||
|
||||
self._run_interval = run_interval
|
||||
self._thread = None
|
||||
self._thread: Thread | None = None
|
||||
self._stop_event = Event()
|
||||
self._startup_time = datetime.now(pytz.UTC)
|
||||
|
||||
@@ -33,13 +35,13 @@ class StatusReporter:
|
||||
DATA_STORE.status.get()["server_owner_callsign"] = SERVER_OWNER_CALLSIGN
|
||||
DATA_STORE.status.store()
|
||||
|
||||
def start(self):
|
||||
def start(self) -> None:
|
||||
"""Start the reporter thread"""
|
||||
|
||||
self._thread = Thread(target=self._run, name="StatusReporter", daemon=True)
|
||||
self._thread.start()
|
||||
|
||||
def stop(self):
|
||||
def stop(self) -> None:
|
||||
"""Stop any threads and prepare for application shutdown"""
|
||||
|
||||
self._stop_event.set()
|
||||
@@ -48,7 +50,7 @@ class StatusReporter:
|
||||
if self._thread.is_alive():
|
||||
logger.warning("Status reporter worker thread did not exit on time and will be killed.")
|
||||
|
||||
def _run(self):
|
||||
def _run(self) -> None:
|
||||
"""Thread entry point: report immediately on startup, then on each interval until stopped"""
|
||||
|
||||
while True:
|
||||
@@ -56,7 +58,7 @@ class StatusReporter:
|
||||
if self._stop_event.wait(timeout=self._run_interval):
|
||||
break
|
||||
|
||||
def _report(self):
|
||||
def _report(self) -> None:
|
||||
"""Write status information"""
|
||||
|
||||
DATA_STORE.status.get()["uptime"] = (datetime.now(pytz.UTC) - self._startup_time).total_seconds()
|
||||
|
||||
Reference in New Issue
Block a user