Fixed transmitting on the same channel

This commit is contained in:
Pünkösd Marcell 2020-10-05 22:19:25 +02:00
parent 4003aa73ac
commit 01fa54e6b6
2 changed files with 18 additions and 11 deletions

View File

@ -11,21 +11,28 @@ import sentry_sdk
from magic_doer import run_everything
def message_callback(ch, method, properties, body):
msg = json.loads(body.decode('utf-8'))
results = run_everything(msg)
def message_callback(channel, method, properties, body):
try:
msg = json.loads(body.decode('utf-8'))
except (UnicodeDecodeError, json.JSONDecodeError) as e:
logging.warning(f"Invalid message recieved: {e}")
return
# TODO: Ez azért elég gettó, de legalább csatlakozik
connection = pika.BlockingConnection(pika.connection.URLParameters(os.environ['PIKA_URL']))
channel = connection.channel()
channel.exchange_declare(exchange=os.environ['PIKA_OUTPUT_EXCHANGE'], exchange_type='fanout')
channel.basic_publish(exchange=os.environ['PIKA_OUTPUT_EXCHANGE'], routing_key='classification-result',
body=json.dumps(results).encode("utf-8"))
results = run_everything(msg) # <- This is where the magic happens
channel.basic_publish(
exchange=os.environ['PIKA_OUTPUT_EXCHANGE'],
routing_key='classification-result',
body=json.dumps(results).encode("utf-8")
)
def main():
logging.basicConfig(stream=sys.stdout, format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s",
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO)
logging.basicConfig(
stream=sys.stdout,
format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s",
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO
)
SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN: