-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
DAQJobHandleStats
and send supervisor messages from main
- Loading branch information
1 parent
b271550
commit 277d9b4
Showing
4 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import time | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
from typing import Dict, Optional | ||
|
||
from daq.base import DAQJob | ||
from daq.models import DAQJobMessage, DAQJobStats | ||
from daq.store.models import DAQJobMessageStore, StorableDAQJobConfig | ||
|
||
DAQJobStatsDict = Dict[type[DAQJob], DAQJobStats] | ||
|
||
|
||
@dataclass | ||
class DAQJobHandleStatsConfig(StorableDAQJobConfig): | ||
pass | ||
|
||
|
||
@dataclass | ||
class DAQJobMessageStats(DAQJobMessage): | ||
stats: DAQJobStatsDict | ||
|
||
|
||
class DAQJobHandleStats(DAQJob): | ||
allowed_message_in_types = [DAQJobMessageStats] | ||
config_type = DAQJobHandleStatsConfig | ||
config: DAQJobHandleStatsConfig | ||
|
||
def start(self): | ||
while True: | ||
self.consume() | ||
time.sleep(1) | ||
|
||
def handle_message(self, message: DAQJobMessageStats) -> bool: | ||
if not super().handle_message(message): | ||
return False | ||
|
||
keys = [ | ||
"daq_job", | ||
"last_message_in_date", | ||
"message_in_count", | ||
"last_message_out_date", | ||
"message_out_count", | ||
] | ||
|
||
def datetime_to_str(dt: Optional[datetime]): | ||
if dt is None: | ||
return "N/A" | ||
return dt.strftime("%Y-%m-%d %H:%M:%S") | ||
|
||
data_to_send = [] | ||
for daq_job_type, msg in message.stats.items(): | ||
data_to_send.append( | ||
[ | ||
daq_job_type.__name__, | ||
datetime_to_str(msg.last_message_in_date), | ||
msg.message_in_count, | ||
datetime_to_str(msg.last_message_out_date), | ||
msg.message_out_count, | ||
] | ||
) | ||
|
||
self.message_out.put( | ||
DAQJobMessageStore( | ||
store_config=self.config.store_config, | ||
daq_job=self, | ||
keys=keys, | ||
data=data_to_send, | ||
) | ||
) | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
from typing import Dict | ||
|
||
from daq.base import DAQJob | ||
from daq.jobs.caen.n1081b import DAQJobN1081B | ||
from daq.jobs.handle_stats import DAQJobHandleStats | ||
from daq.jobs.serve_http import DAQJobServeHTTP | ||
from daq.jobs.store.csv import DAQJobStoreCSV | ||
from daq.jobs.store.root import DAQJobStoreROOT | ||
from daq.jobs.test_job import DAQJobTest | ||
from daq.models import DAQJobStats | ||
|
||
DAQ_JOB_TYPE_TO_CLASS: dict[str, type[DAQJob]] = { | ||
"n1081b": DAQJobN1081B, | ||
"test": DAQJobTest, | ||
"store_csv": DAQJobStoreCSV, | ||
"store_root": DAQJobStoreROOT, | ||
"serve_http": DAQJobServeHTTP, | ||
"handle_stats": DAQJobHandleStats, | ||
} | ||
|
||
DAQJobStatsDict = Dict[type[DAQJob], DAQJobStats] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters