diff --git a/cnn_classification_service/main.py b/cnn_classification_service/main.py index c6b2b99..2c9c684 100644 --- a/cnn_classification_service/main.py +++ b/cnn_classification_service/main.py @@ -24,12 +24,19 @@ def message_callback(channel, method, properties, body): msg = json.loads(body.decode('utf-8')) except (UnicodeDecodeError, json.JSONDecodeError) as e: logging.warning(f"Invalid message recieved: {e}") + channel.basic_ack(delivery_tag=method.delivery_tag) # We don't want this to be requeue return scope.span.log_kv({'event': 'messageParsed', 'sampleTag': msg['tag']}) - with opentracing.tracer.start_active_span('magicDoer.run_everything'): - results = MagicDoer.run_everything(msg) # <- This is where the magic happens + with opentracing.tracer.start_active_span('magicDoer.runEverything'): + try: + results = MagicDoer.run_everything(msg) # <- This is where the magic happens + except Exception as e: + logging.error(f"Something went wrong during AI run: {e}") + logging.exception(e) + channel.basic_nack(delivery_tag=method.delivery_tag, requeue=True) + return if results: channel.basic_publish( @@ -37,7 +44,8 @@ def message_callback(channel, method, properties, body): routing_key='classification-result', body=json.dumps(results).encode("utf-8") ) - channel.basic_ack(delivery_tag=method.delivery_tag) + + channel.basic_ack(delivery_tag=method.delivery_tag) def main():