From 7ddc1b5172f84a3f4cbac2d0166578296f27c40d Mon Sep 17 00:00:00 2001 From: Furkan Date: Thu, 14 Nov 2024 20:43:16 +0300 Subject: [PATCH] refactor: get all daq job classes dynamically - might be useful when this project gets embedded in other projects --- src/daq/jobs/healthcheck.py | 4 ++-- src/daq/types.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/daq/jobs/healthcheck.py b/src/daq/jobs/healthcheck.py index e2baef4..a2c0518 100644 --- a/src/daq/jobs/healthcheck.py +++ b/src/daq/jobs/healthcheck.py @@ -70,7 +70,7 @@ class DAQJobHealthcheck(DAQJob): def __init__(self, config: DAQJobHealthcheckConfig, **kwargs): super().__init__(config, **kwargs) - from daq.types import ALL_DAQ_JOBS, get_daq_job_class + from daq.types import get_all_daq_job_types, get_daq_job_class self._get_daq_job_class = get_daq_job_class self._current_stats = {} @@ -78,7 +78,7 @@ def __init__(self, config: DAQJobHealthcheckConfig, **kwargs): self._healthcheck_stats = [] if config.enable_alerts_on_restart: - for daq_job_type_class in ALL_DAQ_JOBS: + for daq_job_type_class in get_all_daq_job_types(): self._healthcheck_stats.append( HealthcheckStatsItem( alert_info=DAQAlertInfo( diff --git a/src/daq/types.py b/src/daq/types.py index 3ebfcc4..b3291ef 100644 --- a/src/daq/types.py +++ b/src/daq/types.py @@ -14,7 +14,9 @@ from daq.jobs.test_job import DAQJobTest from utils.subclasses import all_subclasses -ALL_DAQ_JOBS = all_subclasses(DAQJob) + +def get_all_daq_job_types(): + return all_subclasses(DAQJob) DAQ_JOB_TYPE_TO_CLASS: dict[str, type[DAQJob]] = { @@ -42,7 +44,7 @@ def get_daq_job_class( f"DAQ job type '{daq_job_type}' is deprecated, please use '{daq_job_class.__name__}' instead" ) else: - for daq_job in ALL_DAQ_JOBS: + for daq_job in get_all_daq_job_types(): if daq_job.__name__ == daq_job_type: daq_job_class = daq_job return daq_job_class