Notification to clients

This commit is contained in:
grossmj committed 2014-03-19 18:48:42 -06:00
1 parent 99cc7345b8
commit c4d9e8371f
5 files changed
+91 -23

No files matched your search

+23 -7
View File
@@ -82,7 +82,8 @@ class IOU(IModule):
self._working_dir = self._projects_dir
self._iourc = ""
self._iou_callback = self.add_periodic_callback(self._check_iou, 5000)
# check every 5 seconds
self._iou_callback = self.add_periodic_callback(self._check_iou_is_alive, 5000)
self._iou_callback.start()
def stop(self):
@@ -97,15 +98,30 @@ class IOU(IModule):
IModule.stop(self) # this will stop the I/O loop
def _check_iou(self):
def _check_iou_is_alive(self):
"""
Periodic callback to check if IOU and iouyap are alive
for each IOU instance.
Sends a notification to the client if not.
"""
for iou_id in self._iou_instances:
iou_instance = self._iou_instances[iou_id]
if iou_instance.started and not iou_instance.is_running():
self.send_notification({"module": self.name,
"id": iou_id,
"name": iou_instance.name,
"message": "IOU is not running"})
if iou_instance.started and (not iou_instance.is_running() or not iou_instance.is_iouyap_running()):
notification = {"module": self.name,
"id": iou_id,
"name": iou_instance.name}
if not iou_instance.is_running():
stdout = iou_instance.read_iou_stdout()
notification["message"] = "IOU has stopped running"
notification["details"] = stdout
self.send_notification("{}.iou_stopped".format(self.name), notification)
elif not iou_instance.is_iouyap_running():
stdout = iou_instance.read_iouyap_stdout()
notification["message"] = "iouyap has stopped running"
notification["details"] = stdout
self.send_notification("{}.iouyap_stopped".format(self.name), notification)
iou_instance.stop()
@IModule.route("iou.reset")
+27 -11
View File
@@ -77,7 +77,8 @@ class IOUDevice(object):
self._command = []
self._process = None
self._iouyap_process = None
self._stdout_file = ""
self._iou_stdout_file = ""
self._iouyap_stdout_file = ""
self._ioucon_thead = None
self._ioucon_thread_stop_event = None
self._host = host
@@ -391,9 +392,9 @@ class IOUDevice(object):
self._update_iouyap_config()
command = [self._iouyap, str(self._id + 512)] # iouyap has always IOU ID + 512
log.info("starting iouyap: {}".format(command))
self._stdout_file = os.path.join(self._working_dir, "iouyap.log")
log.info("logging to {}".format(self._stdout_file))
with open(self._stdout_file, "w") as fd:
self._iouyap_stdout_file = os.path.join(self._working_dir, "iouyap.log")
log.info("logging to {}".format(self._iouyap_stdout_file))
with open(self._iouyap_stdout_file, "w") as fd:
self._iouyap_process = subprocess.Popen(command,
stdout=fd,
stderr=subprocess.STDOUT,
@@ -423,9 +424,9 @@ class IOUDevice(object):
self._command = self._build_command()
try:
log.info("starting IOU: {}".format(self._command))
self._stdout_file = os.path.join(self._working_dir, "iou.log")
log.info("logging to {}".format(self._stdout_file))
with open(self._stdout_file, "w") as fd:
self._iou_stdout_file = os.path.join(self._working_dir, "iou.log")
log.info("logging to {}".format(self._iou_stdout_file))
with open(self._iou_stdout_file, "w") as fd:
self._process = subprocess.Popen(self._command,
stdout=fd,
stderr=subprocess.STDOUT,
@@ -481,19 +482,34 @@ class IOUDevice(object):
self._id))
self._iouyap_process = None
def read_stdout(self):
def read_iou_stdout(self):
"""
Reads the standard output of the IOU process.
Only use when the process has been stopped or has crashed.
"""
output = ""
if self._stdout_file:
if self._iou_stdout_file:
try:
with open(self._stdout_file) as file:
with open(self._iou_stdout_file) as file:
output = file.read()
except EnvironmentError as e:
log.warn("could not read {}: {}".format(self._stdout_file, e))
log.warn("could not read {}: {}".format(self._iou_stdout_file, e))
return output
def read_iouyap_stdout(self):
"""
Reads the standard output of the iouyap process.
Only use when the process has been stopped or has crashed.
"""
output = ""
if self._iouyap_stdout_file:
try:
with open(self._iouyap_stdout_file) as file:
output = file.read()
except EnvironmentError as e:
log.warn("could not read {}: {}".format(self._iouyap_stdout_file, e))
return output
def is_running(self):