added rabbitmq helpers and setup command

This commit is contained in:
Gardient
2021-09-22 22:13:04 +03:00
parent 80e4ddf1a8
commit b50c67ae1e
10 changed files with 98 additions and 4 deletions

View File

@@ -95,3 +95,4 @@ def register_commands(app: Flask):
app.cli.add_command(commands.clean)
app.cli.add_command(commands.urls)
app.cli.add_command(commands.seed)
app.cli.add_command(commands.setup_rabmq)

View File

@@ -5,6 +5,8 @@ from flask import current_app
from flask.cli import with_appcontext
from werkzeug.exceptions import MethodNotAllowed, NotFound
import rmq_helper
from .target.models import Target
from .target_exchange.models import TargetExchange
@@ -91,3 +93,16 @@ def seed():
TargetExchange.ensure_created("")
TargetExchange.ensure_created("webhooks")
@click.command()
@with_appcontext
def setup_rabmq():
"""Set up rabbitMQ"""
for exchange in TargetExchange.query.filter(TargetExchange.name != "").all():
rmq_helper.ensure_exchange_exists(exchange.name)
for target in Target.query.join(Target.exchange).filter(TargetExchange.name == "").all():
rmq_helper.ensure_queue_exists(target.routing_key)
pass

View File

@@ -18,6 +18,7 @@ class Config(object):
JWT_AUTH_HEADER_PREFIX = 'Token'
APISPEC_TITLE = 'MahssageBus API'
APISPEC_VERSION = 'v0.1'
RABBITMQ_HOST = os.environ.get("RABBITMQ_HOST", "localhost")
class ProdConfig(Config):