1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-03-31 12:15:34 -04:00

refactor(threads): migrate APRSRegistryThread to Event-based timing

- Set self.period=CONF.aprs_registry.frequency_seconds in __init__
- Remove counter-based conditional (loop every N seconds pattern)
- Replace time.sleep(1) with self.wait()
- Remove _loop_cnt tracking (use inherited loop_count from base)
- Remove unused time import
This commit is contained in:
Walter Boring 2026-03-24 12:13:31 -04:00
parent 85ebf8a274
commit 505c0fa8a8

View File

@ -1,5 +1,4 @@
import logging
import time
import requests
from oslo_config import cfg
@ -14,11 +13,9 @@ LOG = logging.getLogger('APRSD')
class APRSRegistryThread(aprsd_threads.APRSDThread):
"""This sends service information to the configured APRS Registry."""
_loop_cnt: int = 1
def __init__(self):
super().__init__('APRSRegistryThread')
self._loop_cnt = 1
self.period = CONF.aprs_registry.frequency_seconds
if not CONF.aprs_registry.enabled:
LOG.error(
'APRS Registry is not enabled. ',
@ -34,24 +31,21 @@ class APRSRegistryThread(aprsd_threads.APRSDThread):
)
def loop(self):
# Only call the registry every N seconds
if self._loop_cnt % CONF.aprs_registry.frequency_seconds == 0:
info = {
'callsign': CONF.callsign,
'owner_callsign': CONF.owner_callsign,
'description': CONF.aprs_registry.description,
'service_website': CONF.aprs_registry.service_website,
'software': f'APRSD version {aprsd.__version__} '
'https://github.com/craigerl/aprsd',
}
try:
requests.post(
f'{CONF.aprs_registry.registry_url}',
json=info,
)
except Exception as e:
LOG.error(f'Failed to send registry info: {e}')
info = {
'callsign': CONF.callsign,
'owner_callsign': CONF.owner_callsign,
'description': CONF.aprs_registry.description,
'service_website': CONF.aprs_registry.service_website,
'software': f'APRSD version {aprsd.__version__} '
'https://github.com/craigerl/aprsd',
}
try:
requests.post(
f'{CONF.aprs_registry.registry_url}',
json=info,
)
except Exception as e:
LOG.error(f'Failed to send registry info: {e}')
time.sleep(1)
self._loop_cnt += 1
self.wait()
return True