Commit 22a44ea12479a41275e05eaedf2f73107fee04c4
1 parent
e19c7781ae
Exists in
main
dont consider paddle moving if paddle is below paddle_on torque
Showing 1 changed file with 4 additions and 3 deletions Inline Diff
ssa/alarm/alarmist.py
View file @
22a44ea
""" | 1 | 1 | """ | |
alarmist.py | 2 | 2 | alarmist.py | |
3 | 3 | |||
Periodically checks on SOARS state and processes alarms | 4 | 4 | Periodically checks on SOARS state and processes alarms | |
""" | 5 | 5 | """ | |
6 | 6 | |||
import configparser | 7 | 7 | import configparser | |
import collections | 8 | 8 | import collections | |
import influxdb | 9 | 9 | import influxdb | |
import sys | 10 | 10 | import sys | |
import threading | 11 | 11 | import threading | |
import ssa.alarm.lightstack as lightstack | 12 | 12 | import ssa.alarm.lightstack as lightstack | |
13 | 13 | |||
DEBUG = False | 14 | 14 | DEBUG = False | |
15 | 15 | |||
# bearing coolant is measured by gauge A | 16 | 16 | # bearing coolant is measured by gauge A | |
BEARING_COOLANT_QUERY = """ | 17 | 17 | BEARING_COOLANT_QUERY = """ | |
SELECT last(flow_rate) as flow_rate | 18 | 18 | SELECT last(flow_rate) as flow_rate | |
FROM coolant_flow_rate | 19 | 19 | FROM coolant_flow_rate | |
WHERE meter_id='A' | 20 | 20 | WHERE meter_id='A' | |
""" | 21 | 21 | """ | |
# we have to infer if the paddle is moving based on the motor torque | 22 | 22 | # we have to infer if the paddle is moving based on the motor torque | |
PADDLE_MOVING_QUERY = """ | 23 | 23 | PADDLE_MOVING_QUERY = """ | |
SELECT last(value) as value FROM Torque GROUP BY * | 24 | 24 | SELECT last(value) as value FROM Torque GROUP BY * | |
""" | 25 | 25 | """ | |
# figure out the hottest bearing | 26 | 26 | # figure out the hottest bearing | |
MAX_BEARING_TEMPERATURE_QUERY = """ | 27 | 27 | MAX_BEARING_TEMPERATURE_QUERY = """ | |
SELECT max(temperature) as max_temperature FROM ( | 28 | 28 | SELECT max(temperature) as max_temperature FROM ( | |
SELECT last(temperature) as temperature | 29 | 29 | SELECT last(temperature) as temperature | |
FROM paddle_bearings | 30 | 30 | FROM paddle_bearings | |
WHERE location != 'Ambient' | 31 | 31 | WHERE location != 'Ambient' | |
GROUP BY location | 32 | 32 | GROUP BY location | |
) | 33 | 33 | ) | |
""" | 34 | 34 | """ | |
# grab ambient temperature | 35 | 35 | # grab ambient temperature | |
AMBIENT_TEMPERATURE_QUERY = """ | 36 | 36 | AMBIENT_TEMPERATURE_QUERY = """ | |
SELECT last(temperature) as temperature | 37 | 37 | SELECT last(temperature) as temperature | |
FROM paddle_bearings | 38 | 38 | FROM paddle_bearings | |
WHERE location = 'Ambient' | 39 | 39 | WHERE location = 'Ambient' | |
""" | 40 | 40 | """ | |
41 | 41 | |||
# annoying, but we need to map the measurement name and value key from influxdb | 42 | 42 | # annoying, but we need to map the measurement name and value key from influxdb | |
# onto a key in the soars state object | 43 | 43 | # onto a key in the soars state object | |
MeasurementInfo = collections.namedtuple("MeasurementInfo", "name value_key state_key") | 44 | 44 | MeasurementInfo = collections.namedtuple("MeasurementInfo", "name value_key state_key") | |
45 | 45 | |||
46 | 46 | |||
def dprint(str): | 47 | 47 | def dprint(str): | |
if DEBUG: | 48 | 48 | if DEBUG: | |
print(str) | 49 | 49 | print(str) | |
50 | 50 | |||
51 | 51 | |||
class Alarmist: | 52 | 52 | class Alarmist: | |
def __init__(self): | 53 | 53 | def __init__(self): | |
self.config = configparser.ConfigParser() | 54 | 54 | self.config = configparser.ConfigParser() | |
self.config.read("alarmist_config.ini") | 55 | 55 | self.config.read("alarmist_config.ini") | |
self.state_update_event = threading.Event() | 56 | 56 | self.state_update_event = threading.Event() | |
self.soars_state = ThreadsafeState(self.state_update_event) | 57 | 57 | self.soars_state = ThreadsafeState(self.state_update_event) | |
self.lights = lightstack.LightStack() | 58 | 58 | self.lights = lightstack.LightStack() | |
self.threads = list() | 59 | 59 | self.threads = list() | |
self.threads.append( | 60 | 60 | self.threads.append( | |
PeriodicInfluxdbPoller( | 61 | 61 | PeriodicInfluxdbPoller( | |
interval=2, | 62 | 62 | interval=2, | |
soars_state=self.soars_state, | 63 | 63 | soars_state=self.soars_state, | |
query=BEARING_COOLANT_QUERY, | 64 | 64 | query=BEARING_COOLANT_QUERY, | |
measurment_info=MeasurementInfo( | 65 | 65 | measurment_info=MeasurementInfo( | |
"coolant_flow_rate", "flow_rate", "coolant_flow_rate" | 66 | 66 | "coolant_flow_rate", "flow_rate", "coolant_flow_rate" | |
), | 67 | 67 | ), | |
db_config=self.config["influxdb"], | 68 | 68 | db_config=self.config["influxdb"], | |
) | 69 | 69 | ) | |
) | 70 | 70 | ) | |
self.threads.append( | 71 | 71 | self.threads.append( | |
PeriodicInfluxdbPoller( | 72 | 72 | PeriodicInfluxdbPoller( | |
interval=2, | 73 | 73 | interval=2, | |
soars_state=self.soars_state, | 74 | 74 | soars_state=self.soars_state, | |
query=PADDLE_MOVING_QUERY, | 75 | 75 | query=PADDLE_MOVING_QUERY, | |
measurment_info=MeasurementInfo("Torque", "value", "motor_torque"), | 76 | 76 | measurment_info=MeasurementInfo("Torque", "value", "motor_torque"), | |
db_config=self.config["influxdb"], | 77 | 77 | db_config=self.config["influxdb"], | |
) | 78 | 78 | ) | |
) | 79 | 79 | ) | |
self.threads.append( | 80 | 80 | self.threads.append( | |
PeriodicInfluxdbPoller( | 81 | 81 | PeriodicInfluxdbPoller( | |
interval=5, | 82 | 82 | interval=5, | |
soars_state=self.soars_state, | 83 | 83 | soars_state=self.soars_state, | |
query=MAX_BEARING_TEMPERATURE_QUERY, | 84 | 84 | query=MAX_BEARING_TEMPERATURE_QUERY, | |
measurment_info=MeasurementInfo( | 85 | 85 | measurment_info=MeasurementInfo( | |
"paddle_bearings", "max_temperature", "max_temperature" | 86 | 86 | "paddle_bearings", "max_temperature", "max_temperature" | |
), | 87 | 87 | ), | |
db_config=self.config["influxdb"], | 88 | 88 | db_config=self.config["influxdb"], | |
) | 89 | 89 | ) | |
) | 90 | 90 | ) | |
self.threads.append( | 91 | 91 | self.threads.append( | |
PeriodicInfluxdbPoller( | 92 | 92 | PeriodicInfluxdbPoller( | |
interval=5, | 93 | 93 | interval=5, | |
soars_state=self.soars_state, | 94 | 94 | soars_state=self.soars_state, | |
query=AMBIENT_TEMPERATURE_QUERY, | 95 | 95 | query=AMBIENT_TEMPERATURE_QUERY, | |
measurment_info=MeasurementInfo( | 96 | 96 | measurment_info=MeasurementInfo( | |
"paddle_bearings", "temperature", "ambient_temperature" | 97 | 97 | "paddle_bearings", "temperature", "ambient_temperature" | |
), | 98 | 98 | ), | |
db_config=self.config["influxdb"], | 99 | 99 | db_config=self.config["influxdb"], | |
) | 100 | 100 | ) | |
) | 101 | 101 | ) | |
self.event_watcher_thread = threading.Thread(target=self.check_state) | 102 | 102 | self.event_watcher_thread = threading.Thread(target=self.check_state) | |
self.event_watcher_thread_cancel_flag = threading.Event() | 103 | 103 | self.event_watcher_thread_cancel_flag = threading.Event() | |
104 | 104 | |||
def run(self): | 105 | 105 | def run(self): | |
# start polling threads | 106 | 106 | # start polling threads | |
for thread in self.threads: | 107 | 107 | for thread in self.threads: | |
thread.start() | 108 | 108 | thread.start() | |
# start update event watcher | 109 | 109 | # start update event watcher | |
self.event_watcher_thread.start() | 110 | 110 | self.event_watcher_thread.start() | |
111 | 111 | |||
def cleanup(self): | 112 | 112 | def cleanup(self): | |
# cancel polling loops | 113 | 113 | # cancel polling loops | |
for thread in self.threads: | 114 | 114 | for thread in self.threads: | |
thread.cancel() | 115 | 115 | thread.cancel() | |
# cancel the event watcher thread | 116 | 116 | # cancel the event watcher thread | |
self.event_watcher_thread_cancel_flag.set() | 117 | 117 | self.event_watcher_thread_cancel_flag.set() | |
self.state_update_event.set() | 118 | 118 | self.state_update_event.set() | |
# wait for threads to stop | 119 | 119 | # wait for threads to stop | |
self.join(timeout=1.0) | 120 | 120 | self.join(timeout=1.0) | |
# finally, call cleanup on lights | 121 | 121 | # finally, call cleanup on lights | |
self.lights.cleanup() | 122 | 122 | self.lights.cleanup() | |
123 | 123 | |||
def join(self, timeout=None): | 124 | 124 | def join(self, timeout=None): | |
for thread in self.threads: | 125 | 125 | for thread in self.threads: | |
thread.join(timeout=timeout) | 126 | 126 | thread.join(timeout=timeout) | |
self.event_watcher_thread.join(timeout=timeout) | 127 | 127 | self.event_watcher_thread.join(timeout=timeout) | |
128 | 128 | |||
def check_state(self): | 129 | 129 | def check_state(self): | |
# TODO - create an influxdb client here and log alarm states | 130 | 130 | # TODO - create an influxdb client here and log alarm states | |
131 | 131 | |||
# this method gets run in its own thread, so loop indefinitely, | 132 | 132 | # this method gets run in its own thread, so loop indefinitely, | |
# waking up whenever the state_update_event flag is set | 133 | 133 | # waking up whenever the state_update_event flag is set | |
while self.state_update_event.wait(timeout=None): | 134 | 134 | while self.state_update_event.wait(timeout=None): | |
# exit thread loop if the cancel flag is set | 135 | 135 | # exit thread loop if the cancel flag is set | |
if self.event_watcher_thread_cancel_flag.is_set(): | 136 | 136 | if self.event_watcher_thread_cancel_flag.is_set(): | |
break | 137 | 137 | break | |
# | 138 | 138 | # | |
# update state values that depend on db values | 139 | 139 | # update state values that depend on db values | |
# | 140 | 140 | # | |
# check if paddle is running | 141 | 141 | # check if paddle is running | |
(torque, _) = self.soars_state.get( | 142 | 142 | (torque, _) = self.soars_state.get( | |
"motor_torque", default=(0.0, None), lookback=0 | 143 | 143 | "motor_torque", default=(0.0, None), lookback=0 | |
) | 144 | 144 | ) | |
(previous_torque, _) = self.soars_state.get( | 145 | 145 | (previous_torque, _) = self.soars_state.get( | |
"motor_torque", default=(0.0, None), lookback=1 | 146 | 146 | "motor_torque", default=(0.0, None), lookback=1 | |
) | 147 | 147 | ) | |
(previouser_torque, _) = self.soars_state.get( | 148 | 148 | (previouser_torque, _) = self.soars_state.get( | |
"motor_torque", default=(0.0, None), lookback=2 | 149 | 149 | "motor_torque", default=(0.0, None), lookback=2 | |
) | 150 | 150 | ) | |
paddle_on = torque > float(self.config["thresholds"]["on_torque"]) | 151 | 151 | paddle_on = torque > float(self.config["thresholds"]["on_torque"]) | |
# Check three last points to see if paddle is moving | 152 | 152 | # Check three last points to see if paddle is moving | |
paddle_moving = ( | 153 | 153 | paddle_moving = paddle_on and ( | |
torque > float(self.config["thresholds"]["moving_torque"]) | 154 | 154 | (torque > float(self.config["thresholds"]["moving_torque"])) | |
) or (torque != previous_torque or previous_torque != previouser_torque) | 155 | 155 | or (torque != previous_torque or previous_torque != previouser_torque) | |
156 | ) | |||
# check if coolant is flowing | 156 | 157 | # check if coolant is flowing | |
(coolant_flow_rate, _) = self.soars_state.get( | 157 | 158 | (coolant_flow_rate, _) = self.soars_state.get( | |
"coolant_flow_rate", (0.0, None) | 158 | 159 | "coolant_flow_rate", (0.0, None) | |
) | 159 | 160 | ) | |
coolant_on = coolant_flow_rate > float(self.config["thresholds"]["coolant"]) | 160 | 161 | coolant_on = coolant_flow_rate > float(self.config["thresholds"]["coolant"]) | |
161 | 162 | |||
(ambient, _) = self.soars_state.get("ambient_temperature", (-1, None)) | 162 | 163 | (ambient, _) = self.soars_state.get("ambient_temperature", (-1, None)) | |
(max_bearing, _) = self.soars_state.get("max_temperature", (-1, None)) | 163 | 164 | (max_bearing, _) = self.soars_state.get("max_temperature", (-1, None)) | |
ambient_delta = float( | 164 | 165 | ambient_delta = float( | |
self.config["thresholds"]["ambient_temperature_delta"] | 165 | 166 | self.config["thresholds"]["ambient_temperature_delta"] | |
) | 166 | 167 | ) | |
bearing_temperature_warning = False | 167 | 168 | bearing_temperature_warning = False | |
if ambient > 0 and max_bearing > 0: | 168 | 169 | if ambient > 0 and max_bearing > 0: | |
if max_bearing > ambient + ambient_delta: | 169 | 170 | if max_bearing > ambient + ambient_delta: | |
bearing_temperature_warning = True | 170 | 171 | bearing_temperature_warning = True | |
171 | 172 | |||
dprint( | 172 | 173 | dprint( | |
f"State: paddle_on: {paddle_on}, paddle_moving: {paddle_moving}, coolant_on: {coolant_on}" | 173 | 174 | f"State: paddle_on: {paddle_on}, paddle_moving: {paddle_moving}, coolant_on: {coolant_on}" | |
) | 174 | 175 | ) | |
dprint(f"Ambient temperature: {ambient}C Hottest bearing: {max_bearing}C") | 175 | 176 | dprint(f"Ambient temperature: {ambient}C Hottest bearing: {max_bearing}C") | |
176 | 177 | |||
# | 177 | 178 | # | |
# run checks to throw alarms | 178 | 179 | # run checks to throw alarms | |
# | 179 | 180 | # | |
warning = False | 180 | 181 | warning = False | |
alarm = False | 181 | 182 | alarm = False | |
# is paddle running? (solid white, no problems) | 182 | 183 | # is paddle running? (solid white, no problems) | |
if paddle_on: | 183 | 184 | if paddle_on: | |
self.lights.on(lightstack.Channel.White) | 184 | 185 | self.lights.on(lightstack.Channel.White) | |
else: | 185 | 186 | else: | |
self.lights.off(lightstack.Channel.White) | 186 | 187 | self.lights.off(lightstack.Channel.White) | |
# is paddle moving? (solid green, no problems) | 187 | 188 | # is paddle moving? (solid green, no problems) | |
if paddle_moving: | 188 | 189 | if paddle_moving: | |
self.lights.on(lightstack.Channel.Green) | 189 | 190 | self.lights.on(lightstack.Channel.Green) | |
else: | 190 | 191 | else: | |
self.lights.off(lightstack.Channel.Green) | 191 | 192 | self.lights.off(lightstack.Channel.Green) | |
# is water running? (solid blue, no problems) | 192 | 193 | # is water running? (solid blue, no problems) | |
if coolant_on: | 193 | 194 | if coolant_on: | |
self.lights.on(lightstack.Channel.Blue) | 194 | 195 | self.lights.on(lightstack.Channel.Blue) | |
else: | 195 | 196 | else: | |
self.lights.off(lightstack.Channel.Blue) | 196 | 197 | self.lights.off(lightstack.Channel.Blue) | |
# is paddle moving without water? (alarm state and flash blue) | 197 | 198 | # is paddle moving without water? (alarm state and flash blue) | |
if paddle_moving and not coolant_on: | 198 | 199 | if paddle_moving and not coolant_on: | |
self.lights.start_blink(0.5, lightstack.Channel.Blue) | 199 | 200 | self.lights.start_blink(0.5, lightstack.Channel.Blue) | |
alarm = True | 200 | 201 | alarm = True | |
else: | 201 | 202 | else: | |
self.lights.stop_blink(lightstack.Channel.Blue) | 202 | 203 | self.lights.stop_blink(lightstack.Channel.Blue) | |
# is the hottest bearing above ambient? (warning) | 203 | 204 | # is the hottest bearing above ambient? (warning) | |
if bearing_temperature_warning: | 204 | 205 | if bearing_temperature_warning: | |
warning = True | 205 | 206 | warning = True | |
# TODO - piston temps > 100F? (flash yellow w/ buzzer) | 206 | 207 | # TODO - piston temps > 100F? (flash yellow w/ buzzer) | |
207 | 208 | |||
# did any warnings get thrown? (turn on yellow flashing) | 208 | 209 | # did any warnings get thrown? (turn on yellow flashing) | |
if warning: | 209 | 210 | if warning: | |
self.lights.start_blink(0.5, lightstack.Channel.Yellow) | 210 | 211 | self.lights.start_blink(0.5, lightstack.Channel.Yellow) | |
else: | 211 | 212 | else: | |
self.lights.stop_blink(lightstack.Channel.Yellow) | 212 | 213 | self.lights.stop_blink(lightstack.Channel.Yellow) | |
213 | 214 | |||
# | 214 | 215 | # | |
# did any alarm want to turn on the buzzer? | 215 | 216 | # did any alarm want to turn on the buzzer? | |
# | 216 | 217 | # | |
if alarm: | 217 | 218 | if alarm: | |
self.lights.start_blink(0.3, lightstack.Channel.Red) | 218 | 219 | self.lights.start_blink(0.3, lightstack.Channel.Red) | |
self.lights.start_blink(0.3, lightstack.Channel.Buzzer) | 219 | 220 | self.lights.start_blink(0.3, lightstack.Channel.Buzzer) | |
else: | 220 | 221 | else: | |
self.lights.stop_blink(lightstack.Channel.Red) | 221 | 222 | self.lights.stop_blink(lightstack.Channel.Red) | |
self.lights.stop_blink(lightstack.Channel.Buzzer) | 222 | 223 | self.lights.stop_blink(lightstack.Channel.Buzzer) | |
223 | 224 | |||
# clear event flag | 224 | 225 | # clear event flag | |
self.state_update_event.clear() | 225 | 226 | self.state_update_event.clear() | |
226 | 227 | |||
227 | 228 | |||
class RingBuffer: | 228 | 229 | class RingBuffer: | |
def __init__(self, size): | 229 | 230 | def __init__(self, size): | |
self.size = size | 230 | 231 | self.size = size | |
self.data = [None] * size | 231 | 232 | self.data = [None] * size | |
self.head = -1 | 232 | 233 | self.head = -1 | |
233 | 234 | |||
def __getitem__(self, index=0): | 234 | 235 | def __getitem__(self, index=0): | |
if index >= self.size: | 235 | 236 | if index >= self.size: | |
raise Exception(f"Index out of bounds (index: {index}, size: {self.size})") | 236 | 237 | raise Exception(f"Index out of bounds (index: {index}, size: {self.size})") | |
internal_index = (self.head - index) % self.size | 237 | 238 | internal_index = (self.head - index) % self.size | |
return self.data[internal_index] | 238 | 239 | return self.data[internal_index] | |
239 | 240 | |||
def get(self, index=0, default=None): | 240 | 241 | def get(self, index=0, default=None): | |
val = self[index] | 241 | 242 | val = self[index] | |
return val if val is not None else default | 242 | 243 | return val if val is not None else default | |
243 | 244 | |||
def push(self, item): | 244 | 245 | def push(self, item): | |
self.head = (self.head + 1) % self.size | 245 | 246 | self.head = (self.head + 1) % self.size | |
self.data[self.head] = item | 246 | 247 | self.data[self.head] = item | |
247 | 248 | |||
248 | 249 | |||
# global state object protected by a lock | 249 | 250 | # global state object protected by a lock | |
# only update values if the new timestamp differs from the most recent item's timestamp | 250 | 251 | # only update values if the new timestamp differs from the most recent item's timestamp | |
# store history of past [lookback] items | 251 | 252 | # store history of past [lookback] items | |
class ThreadsafeState: | 252 | 253 | class ThreadsafeState: | |
def __init__(self, update_event, lookback=5): | 253 | 254 | def __init__(self, update_event, lookback=5): | |
self.lookback = lookback | 254 | 255 | self.lookback = lookback | |
self.state = dict() | 255 | 256 | self.state = dict() | |
self.lock = threading.RLock() | 256 | 257 | self.lock = threading.RLock() | |
self.update_event = update_event | 257 | 258 | self.update_event = update_event | |
258 | 259 | |||
def set(self, key, value, time): | 259 | 260 | def set(self, key, value, time): | |
with self.lock: | 260 | 261 | with self.lock: | |
if self.state.get(key, None) is None: | 261 | 262 | if self.state.get(key, None) is None: | |
self._init_entry(key) | 262 | 263 | self._init_entry(key) | |
history = self.state.get(key) | 263 | 264 | history = self.state.get(key) | |
item = history.get() | 264 | 265 | item = history.get() | |
if item is None: | 265 | 266 | if item is None: | |
history.push((value, time)) | 266 | 267 | history.push((value, time)) | |
self.update_event.set() | 267 | 268 | self.update_event.set() | |
else: | 268 | 269 | else: | |
(_, previous_time) = item | 269 | 270 | (_, previous_time) = item | |
if time != previous_time: | 270 | 271 | if time != previous_time: | |
history.push((value, time)) | 271 | 272 | history.push((value, time)) | |
self.update_event.set() | 272 | 273 | self.update_event.set() | |
dprint(f"ThreadsafeState: set: {key}: {value} ({time})") | 273 | 274 | dprint(f"ThreadsafeState: set: {key}: {value} ({time})") | |
274 | 275 | |||
def _init_entry(self, key): | 275 | 276 | def _init_entry(self, key): | |
with self.lock: | 276 | 277 | with self.lock: | |
self.state[key] = RingBuffer(self.lookback) | 277 | 278 | self.state[key] = RingBuffer(self.lookback) | |
278 | 279 | |||
def get(self, key, default=None, lookback=0): | 279 | 280 | def get(self, key, default=None, lookback=0): | |
with self.lock: | 280 | 281 | with self.lock: | |
history = self.state.get(key, None) | 281 | 282 | history = self.state.get(key, None) | |
if history is None: | 282 | 283 | if history is None: | |
return default | 283 | 284 | return default | |
else: | 284 | 285 | else: | |
return history.get(index=lookback, default=default) | 285 | 286 | return history.get(index=lookback, default=default) | |
286 | 287 | |||
287 | 288 | |||
# extend the Timer thread object to run repeatedly. Subclass this. | 288 | 289 | # extend the Timer thread object to run repeatedly. Subclass this. | |
class RepeatedTimer(threading.Timer): | 289 | 290 | class RepeatedTimer(threading.Timer): | |
def __init__(self, interval): | 290 | 291 | def __init__(self, interval): | |
# Timer constructer expects a callback function, but we don't care | 291 | 292 | # Timer constructer expects a callback function, but we don't care | |
# about that, so just pass None | 292 | 293 | # about that, so just pass None | |
super(RepeatedTimer, self).__init__(interval, None) | 293 | 294 | super(RepeatedTimer, self).__init__(interval, None) | |
294 | 295 | |||
# override Timer's run method to loop on our injest_data function | 295 | 296 | # override Timer's run method to loop on our injest_data function | |
# wait will block while loop for timeout interval | 296 | 297 | # wait will block while loop for timeout interval | |
# calling timer.cancel() sets the finish flag and exits the loop | 297 | 298 | # calling timer.cancel() sets the finish flag and exits the loop | |
def run(self): | 298 | 299 | def run(self): | |
while not self.finished.wait(timeout=self.interval): | 299 | 300 | while not self.finished.wait(timeout=self.interval): | |
self.do_work() | 300 | 301 | self.do_work() | |
301 | 302 | |||
def do_work(self): | 302 | 303 | def do_work(self): | |
raise Exception( | 303 | 304 | raise Exception( | |
"RepeatedTimer baseclass do_work() called. Override this method in a subclass" | 304 | 305 | "RepeatedTimer baseclass do_work() called. Override this method in a subclass" | |
) | 305 | 306 | ) | |
306 | 307 | |||
307 | 308 | |||
# makes a [query] to influxdb every [interval] | 308 | 309 | # makes a [query] to influxdb every [interval] | |
# influxdb returns a resultset object: | 309 | 310 | # influxdb returns a resultset object: | |
# https://influxdb-python.readthedocs.io/en/latest/resultset.html#resultset | 310 | 311 | # https://influxdb-python.readthedocs.io/en/latest/resultset.html#resultset | |
class PeriodicInfluxdbPoller(RepeatedTimer): | 311 | 312 | class PeriodicInfluxdbPoller(RepeatedTimer): | |
def __init__(self, interval, soars_state, query, measurment_info, db_config): | 312 | 313 | def __init__(self, interval, soars_state, query, measurment_info, db_config): | |
super(PeriodicInfluxdbPoller, self).__init__(interval) | 313 | 314 | super(PeriodicInfluxdbPoller, self).__init__(interval) | |
self.soars_state = soars_state | 314 | 315 | self.soars_state = soars_state | |
self.query = query | 315 | 316 | self.query = query |