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 from magic_doer import run_everything
def message_callback(ch, method, properties, body): def message_callback(channel, method, properties, body):
try:
msg = json.loads(body.decode('utf-8')) msg = json.loads(body.decode('utf-8'))
results = run_everything(msg) 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 results = run_everything(msg) # <- This is where the magic happens
connection = pika.BlockingConnection(pika.connection.URLParameters(os.environ['PIKA_URL']))
channel = connection.channel() channel.basic_publish(
channel.exchange_declare(exchange=os.environ['PIKA_OUTPUT_EXCHANGE'], exchange_type='fanout') exchange=os.environ['PIKA_OUTPUT_EXCHANGE'],
channel.basic_publish(exchange=os.environ['PIKA_OUTPUT_EXCHANGE'], routing_key='classification-result', routing_key='classification-result',
body=json.dumps(results).encode("utf-8")) body=json.dumps(results).encode("utf-8")
)
def main(): def main():
logging.basicConfig(stream=sys.stdout, format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s", logging.basicConfig(
level=logging.DEBUG if '--debug' in sys.argv else logging.INFO) 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") SENTRY_DSN = os.environ.get("SENTRY_DSN")
if SENTRY_DSN: if SENTRY_DSN: