add proper rabbitMQ extension
This commit is contained in:
@@ -2,7 +2,7 @@ from flask import Flask, Blueprint
|
||||
|
||||
from . import commands, login, target_exchange, target, registration
|
||||
from .exceptions import ApiException
|
||||
from .extensions import db, migrate, jwt, apispec
|
||||
from .extensions import db, migrate, jwt, apispec, rabbit
|
||||
from .settings import ProdConfig, Config
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ def register_extensions(app: Flask):
|
||||
migrate.init_app(app, db)
|
||||
jwt.init_app(app)
|
||||
apispec.init_app(app)
|
||||
rabbit.init_app(app)
|
||||
|
||||
|
||||
def register_blueprints(app: Flask):
|
||||
@@ -82,6 +83,7 @@ def register_shellcontext(app: Flask):
|
||||
"""Shell context objects."""
|
||||
return {
|
||||
'db': db,
|
||||
'rabbit': rabbit,
|
||||
'TargetExchange': target_exchange.models.TargetExchange,
|
||||
'Target': target.models.Target,
|
||||
'Registration': registration.models.Registration,
|
||||
|
||||
@@ -5,7 +5,7 @@ from flask import current_app
|
||||
from flask.cli import with_appcontext
|
||||
from werkzeug.exceptions import MethodNotAllowed, NotFound
|
||||
|
||||
import rmq_helper
|
||||
from .extensions import rabbit
|
||||
from .target.models import Target
|
||||
from .target_exchange.models import TargetExchange
|
||||
|
||||
@@ -100,9 +100,9 @@ def seed():
|
||||
def setup_rabmq():
|
||||
"""Set up rabbitMQ"""
|
||||
for exchange in TargetExchange.query.filter(TargetExchange.name != "").all():
|
||||
rmq_helper.ensure_exchange_exists(exchange.name)
|
||||
rabbit.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)
|
||||
rabbit.ensure_queue_exists(target.routing_key)
|
||||
|
||||
pass
|
||||
|
||||
@@ -2,6 +2,7 @@ from flask_apispec import FlaskApiSpec
|
||||
from flask_jwt_extended import JWTManager
|
||||
from flask_migrate import Migrate
|
||||
from flask_sqlalchemy import SQLAlchemy, Model
|
||||
from rmq_helper import RabbitMQ
|
||||
|
||||
|
||||
class CRUDMixin(Model):
|
||||
@@ -36,3 +37,4 @@ db = SQLAlchemy(model_class=CRUDMixin)
|
||||
migrate = Migrate()
|
||||
jwt = JWTManager()
|
||||
apispec = FlaskApiSpec()
|
||||
rabbit = RabbitMQ()
|
||||
|
||||
Reference in New Issue
Block a user