示例#1
0
def test_urlrabbitmq_creates_instances_of_rabbitmq_broker():
    # Given a URL connection string
    url = "amqp://127.0.0.1:5672"

    # When I pass that to URLRabbitmqBroker
    broker = URLRabbitmqBroker(url)

    # Then I should get back a RabbitmqBroker
    assert isinstance(broker, RabbitmqBroker)
示例#2
0
def test_urlrabbitmq_creates_instances_of_rabbitmq_broker():
    # Given a URL connection string
    url = "amqp://%s:%[email protected]:5672" % (RABBITMQ_USERNAME,
                                           RABBITMQ_PASSWORD)

    # When I pass that to URLRabbitmqBroker
    broker = URLRabbitmqBroker(url)

    # Then I should get back a RabbitmqBroker
    assert isinstance(broker, RabbitmqBroker)
示例#3
0
from sqlalchemy import Column, DateTime, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql import func
from threading import local


app = Flask(__name__)

database_url = os.getenv("DATABASE_URL", os.getenv("SQLITE_URL"))
database = create_engine(database_url)
Model = declarative_base()
Session = sessionmaker(bind=database)

broker_url = os.getenv("CLOUDAMQP_URL", os.getenv("BROKER_URL"))
broker = URLRabbitmqBroker(broker_url)
dramatiq.set_broker(broker)


class AppContextMiddleware(dramatiq.Middleware):
    state = local()

    def __init__(self, app):
        self.app = app

    def before_process_message(self, broker, message):
        context = self.app.app_context()
        context.push()

        self.state.context = context
示例#4
0
def setup_dramatiq():
    if os.environ.get('AMQP_URL'):
        broker = URLRabbitmqBroker(os.environ['AMQP_URL'])
    else:
        broker = RedisBroker(url=os.environ['REDIS_URL'])
    dramatiq.set_broker(broker)