From 505c0fa8a8444f98dd15c2b7ce002d9156352684 Mon Sep 17 00:00:00 2001 From: Walter Boring Date: Tue, 24 Mar 2026 12:13:31 -0400 Subject: [PATCH] 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 --- aprsd/threads/registry.py | 40 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/aprsd/threads/registry.py b/aprsd/threads/registry.py index 7139821..24765ee 100644 --- a/aprsd/threads/registry.py +++ b/aprsd/threads/registry.py @@ -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