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"))