Fixed transmitting on the same channel
This commit is contained in:
parent
4003aa73ac
commit
01fa54e6b6
0
cnn_classification_service/classifier_cache.py
Normal file
0
cnn_classification_service/classifier_cache.py
Normal 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):
|
||||||
msg = json.loads(body.decode('utf-8'))
|
try:
|
||||||
results = run_everything(msg)
|
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
|
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user