From e8717ef0958bfed90176e467288fcadf217883b9 Mon Sep 17 00:00:00 2001 From: dciangot Date: Thu, 27 Oct 2016 13:01:09 +0200 Subject: [PATCH] Fix exception and disconnect for Dashboard script --- bin/DashboardNotifier.py | 17 +++++++++-------- src/python/AsyncStageOut/TransferDaemon.py | 14 +++++--------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/bin/DashboardNotifier.py b/bin/DashboardNotifier.py index 3086573..629c5aa 100644 --- a/bin/DashboardNotifier.py +++ b/bin/DashboardNotifier.py @@ -3,24 +3,24 @@ from __future__ import division import stomp import json -import traceback import os import sys import datetime import logging from multiprocessing import Process -def reportToAmq(filePath, logging, conn): + +def reportToAmq(filePath, log, connect): """ """ jsonData=open(filePath) message = json.load(jsonData) - logging.debug("Producing...%s" % message) + log.debug("Producing...%s" % message) try: messageDict = json.dumps(message) - conn.send(messageDict, destination=authParams['MSG_QUEUE'] ) - except Exception as ex: - logging.exception("Error contacting Message Broker or reading json") + connect.send(messageDict, destination=authParams['MSG_QUEUE'] ) + except Exception: + log.exception("Error contacting Message Broker or reading json") sys.exit(1) logging.basicConfig(filename='/data/srv/asyncstageout/current/config/log.config', level=logging.DEBUG) @@ -30,7 +30,7 @@ def reportToAmq(filePath, logging, conn): f = open(amqAuthFile) authParams = json.loads(f.read()) f.close() -except Exception as ex: +except Exception: logging.exception("Error loading auth params") sys.exit(1) @@ -39,8 +39,9 @@ def reportToAmq(filePath, logging, conn): conn = stomp.Connection(host, authParams['MSG_USER'], authParams['MSG_PWD']) conn.start() conn.connect() -except Exception as ex: +except Exception: logging.exception("Error contacting Message Broker") + conn.disconnect() sys.exit(1) for dashboardFile in os.listdir("/tmp/DashboardReport"): diff --git a/src/python/AsyncStageOut/TransferDaemon.py b/src/python/AsyncStageOut/TransferDaemon.py index 41ffa8c..ad9cf31 100644 --- a/src/python/AsyncStageOut/TransferDaemon.py +++ b/src/python/AsyncStageOut/TransferDaemon.py @@ -74,20 +74,16 @@ def __init__(self, config): try: os.makedirs(self.dropbox_dir) except OSError as e: - if e.errno == errno.EEXIST: - pass - else: - self.logger.error('Unknown error in mkdir' % e.errno) + if not e.errno == errno.EEXIST: + self.logger.exception('Unknown error in mkdir' % e.errno) raise - if not os.path.isdir("/tmp/DashboardReport"): + if not os.path.isdir("/tmp/DashboardReport"): try: os.makedirs("/tmp/DashboardReport") except OSError as e: - if e.errno == errno.EEXIST: - pass - else: - self.logger.error('Unknown error in mkdir' % e.errno) + if not e.errno == errno.EEXIST: + self.logger.exception('Unknown error in mkdir' % e.errno) raise server = CouchServer(dburl=self.config.couch_instance, ckey=self.config.opsProxy, cert=self.config.opsProxy)