from contextlib import contextmanager
from flask import current_app
from redis import StrictRedis
import rq


_queue = None


def get_queue():
    global _queue
    if _queue is None:
        _queue = create_queue()
    return _queue


def create_queue():
    """Connect to Redis and create the RQ. Since this is not imported
    directly, it is a convenient place to mock for tests that don't
    care about the queue.
    """
    redis = StrictRedis(
        host=current_app.config.get('REDIS_HOST','localhost'),
        port=current_app.config.get('REDIS_PORT',6379),
        password=current_app.config.get('REDIS_PASSWORD',None)
    )
    return rq.Queue('redwind:low', connection=redis)


@contextmanager
def async_app_context(app_config):
    from redwind import create_app
    app = create_app(app_config)
    with app.app_context():
        yield

from contextlib import contextmanager
from redis import StrictRedis
import rq


_queue = None


def get_queue():
    global _queue
    if _queue is None:
        _queue = create_queue()
    return _queue


def create_queue():
    """Connect to Redis and create the RQ. Since this is not imported
    directly, it is a convenient place to mock for tests that don't
    care about the queue.
    """
    redis = StrictRedis()
    return rq.Queue('redwind:low', connection=redis)


@contextmanager
def async_app_context(app_config):
    from redwind import create_app
    app = create_app(app_config)
    with app.app_context():
        yield

Revert "Added configuration options for Redis"
Revert "Added configuration options for Redis"

This reverts commit 80129aac1fb4471e7a519b8f86df2db0b978903a.
