made service less crashy
continuous-integration/drone/push Build was killed Details

This commit is contained in:
Pünkösd Marcell 2021-08-04 15:57:29 +02:00
parent d17ab9d401
commit ea968f9d18
1 changed files with 11 additions and 3 deletions

View File

@ -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():