From 67bc22963c6928dc163a5fd8898ba6ba2856209d Mon Sep 17 00:00:00 2001 From: marcsello Date: Sat, 20 Jun 2020 20:57:23 +0200 Subject: [PATCH] Pikachu hotficc --- classification_service/mule.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/classification_service/mule.py b/classification_service/mule.py index f637429..103ee48 100644 --- a/classification_service/mule.py +++ b/classification_service/mule.py @@ -78,14 +78,16 @@ def run_classification(task, target_class_name: str): def main(): - connection = pika.BlockingConnection(pika.connection.URLParameters(os.environ['PIKA_URL'])) - channel = connection.channel() - channel.exchange_declare(exchange=os.environ['PIKA_EXCHANGE'], exchange_type='fanout') while True: message = uwsgi.mule_get_msg() task = json.loads(message) results = run_classification(task, os.environ['TARGET_CLASS_NAME']) + + # For some reason Pika loves to disconnect randomly... + connection = pika.BlockingConnection(pika.connection.URLParameters(os.environ['PIKA_URL'])) + channel = connection.channel() + channel.exchange_declare(exchange=os.environ['PIKA_EXCHANGE'], exchange_type='fanout') channel.basic_publish(exchange=os.environ['PIKA_EXCHANGE'], routing_key='classification-result', body=json.dumps(results).encode("utf-8"))