made service less crashy
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Pünkösd Marcell 2021-08-04 15:57:29 +02:00
parent d17ab9d401
commit ea968f9d18

View File

@ -24,12 +24,19 @@ def message_callback(channel, method, properties, body):
msg = json.loads(body.decode('utf-8')) msg = json.loads(body.decode('utf-8'))
except (UnicodeDecodeError, json.JSONDecodeError) as e: except (UnicodeDecodeError, json.JSONDecodeError) as e:
logging.warning(f"Invalid message recieved: {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 return
scope.span.log_kv({'event': 'messageParsed', 'sampleTag': msg['tag']}) scope.span.log_kv({'event': 'messageParsed', 'sampleTag': msg['tag']})
with opentracing.tracer.start_active_span('magicDoer.run_everything'): with opentracing.tracer.start_active_span('magicDoer.runEverything'):
results = MagicDoer.run_everything(msg) # <- This is where the magic happens 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: if results:
channel.basic_publish( channel.basic_publish(
@ -37,7 +44,8 @@ def message_callback(channel, method, properties, body):
routing_key='classification-result', routing_key='classification-result',
body=json.dumps(results).encode("utf-8") 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(): def main():