Skip to content

Commit

Permalink
refactor: get all daq job classes dynamically
Browse files Browse the repository at this point in the history
- might be useful when this project gets embedded in other projects
  • Loading branch information
furkan-bilgin committed Nov 14, 2024
1 parent eb9ba7c commit 7ddc1b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/daq/jobs/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ 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 = {}

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(
Expand Down
6 changes: 4 additions & 2 deletions src/daq/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {
Expand Down Expand Up @@ -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

0 comments on commit 7ddc1b5

Please sign in to comment.