From 2f94bac95029acdbcb51ad76f6c0430937e4915e Mon Sep 17 00:00:00 2001 From: andrewso <9V5f1FkzI2LD> Date: Tue, 6 Oct 2020 18:57:32 +0100 Subject: [PATCH] [06.10.20] Log timing and amq error handling --- src/pricing/collector.py | 10 +++++----- src/utils/activemqConnect.py | 23 +++++++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/pricing/collector.py b/src/pricing/collector.py index 0985818..deabfb9 100644 --- a/src/pricing/collector.py +++ b/src/pricing/collector.py @@ -38,7 +38,7 @@ def averager(type): averagePrice = round(averagePrice, 2) log("Hourly Price for ({}) is {}".format(timestamp ,averagePrice), 'INFO') - sleep(0.05) + sleep(0.5) return averagePrice, timestamp @@ -124,9 +124,9 @@ def sentToArtemis(c_type, timestamp, av_price, high, low, vol, o_price, c_price) messageJson = json.dumps(message, indent = 4) log("Sending message to PricingSave queue", 'INFO') - sleep(0.05) + sleep(0.5) log("Message: {}".format(message), 'INFO') - sleep(0.05) + sleep(0.5) activeMQSender(messageJson) @@ -163,12 +163,12 @@ def collector(c_type): schedule.every().hour.at(time).do(collector, c_type).tag("collector") log("Collection will run again at {} every hour".format(time), 'INFO') - sleep(0.05) + sleep(0.5) # Dynamically Spin up Child process for each type wanting to track def collectorMain(c_type): log("== Historical Price Collector ==", 'INFO') - sleep(0.05) + sleep(0.5) collector(c_type) diff --git a/src/utils/activemqConnect.py b/src/utils/activemqConnect.py index d62e240..1e4fd5f 100644 --- a/src/utils/activemqConnect.py +++ b/src/utils/activemqConnect.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import stomp -import os +import os, sys from src.utils.jsonLogger import log from time import sleep @@ -22,12 +22,19 @@ def activeMQSender(message): addr, port, mqUser, mqPass = keys().returnKeys() log("Attempting Connection to Artemis...", 'INFO') - sleep(0.05) + sleep(1) + try: + con = stomp.Connection([(addr, port)], auto_content_length=False) + try: + con.connect( mqUser, mqPass, wait=True) - con = stomp.Connection([(addr, port)], auto_content_length=False) - con.connect( mqUser, mqPass, wait=True) - - con.send("PricingSave", message, content_type="application/json", headers={"Content-Type":"application/json"}) - - con.disconnect() + con.send("PricingSave", message, content_type="application/json", headers={"Content-Type":"application/json"}) + except: + e = sys.exc_info()[0] + log("And Error occurred when sending to AMQ :: {}".format(e), 'ERR') + con.disconnect() + con.disconnect() + except: + e = sys.exc_info()[0] + log("And Error occurred when connecting to AMQ :: {}".format(e), 'ERR')