connect on demand
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-10-19 23:26:59 +02:00
parent 483c97e980
commit dadb6508b3
4 changed files with 15 additions and 301 deletions

View File

@ -8,7 +8,7 @@ from db import db
from models import SampleMetadata
from schemas import SampleSchema, SampleMetadataSchema
from config import *
from fpika import fpika
import pika
"""
Flask Restful endpoints
@ -76,10 +76,20 @@ class SampleResource(Resource):
soundfile,
soundfile.content_type,
{'Content-Length': soundfile.content_length})}).raise_for_status()
ch = fpika.channel()
ch.basic_publish(exchange=RABBITMQ_EXCHANGE, routing_key='feature',
body=json.dumps({'tag': generated_tag}).encode('UTF-8'))
fpika.return_channel(ch)
credentials = pika.PlainCredentials(current_app.config['FLASK_PIKA_PARAMS']['username'],
current_app.config['FLASK_PIKA_PARAMS']['password'])
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=current_app.config['FLASK_PIKA_PARAMS']['host'],
credentials=credentials,
heartbeat=0,
socket_timeout=5))
channel = connection.channel()
channel.exchange_declare(exchange=current_app.config['FLASK_PIKA_PARAMS']['EXCHANGE_NAME'],
exchange_type='fanout')
channel.basic_publish(exchange=current_app.config['FLASK_PIKA_PARAMS']['EXCHANGE_NAME'],
routing_key='feature',
body=json.dumps({'tag': generated_tag}).encode('UTF-8'))
connection.close()
except Exception as e:
current_app.logger.exception(e)
db.session.rollback()