def make_celery(app):
    celery = Celery(app.import_name,
                    backend=app.config['CELERY_RESULT_BACKEND'],
                    broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task

    class ContextTask(TaskBase):
        abstract = True

        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)

    celery.Task = ContextTask
    return celery
Example #2
0
def app_context(request):
    """Initializes the application and sets the app context to avoid needing 'with app.app_context():'.

    This needs to run first, so it has been placed in the top-level conftest.py and the function starts with the letter
    'a'.
    """
    app = Flask(__name__)
    app.config['CELERY_ALWAYS_EAGER'] = True
    app.config['TESTING'] = True
    app.config['REDIS_URL'] = 'redis://localhost/1'
    app.config['CELERY_BROKER_URL'] = 'redis://localhost/1'
    app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost/1'
    Celery(app)
    Redis(app)
    context = app.app_context()
    context.push()
    request.addfinalizer(lambda: context.pop())
Example #3
0
"""
Instantiate all extensions used by the application here
"""
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()

from flask_migrate import Migrate
migrate = Migrate()

from flask.ext.cache import Cache
cache = Cache(config={'CACHE_TYPE': 'redis',
                      'CACHE_KEY_PREFIX': 'abort_cache',
                      'CACHE_REDIS_URL': 'redis://localhost:6379',
                      'CACHE_REDIS_PORT': '6379',
                      'CACHE_REDIS_HOST': 'localhost'})

from flask.ext.celery import Celery
celery = Celery()
Example #4
0
from flask import Flask

from flask_heroku import Heroku
from flask_sslify import SSLify
from raven.contrib.flask import Sentry
from flask.ext.celery import Celery

app = Flask(__name__)
app.secret_key = os.environ.get('APP_SECRET', 'some-secret-key')
app.debug = 'DEBUG' in os.environ

# Use gevent workers for celery.
app.config['CELERYD_POOL'] = 'gevent'

# Bootstrap Heroku environment variables.
heroku = Heroku(app)

# Redirect urls to https
sslify = SSLify(app)

# Setup error collection
sentry = Sentry(app)

# Task queue
celery = Celery(app)


@app.route('/')
def hello_world():
    return 'Hello World!'
def test_one_dumb_line():
    app = FakeApp()
    Celery(app)
    assert 'celery' in app.extensions
def test_multiple():
    assert 'celery' in current_app.extensions

    with pytest.raises(ValueError):
        Celery(current_app)
Example #7
0
def test_one_dumb_line():
    flask_app = FakeApp()
    Celery(flask_app)
    assert 'celery' in flask_app.extensions
Example #8
0

# Create the Flask-Bcrypt's instance
bcrypt = Bcrypt()

# Create the Flask-OpenID's instance
openid = OpenID()

# Create the Flask-Principal's instance
principals = Principal()

# Create the Flask-Restful's instance
restful_api = Api()

# Create the Flask-Celery-Helper's instance
flask_celery = Celery()

# Create the Flask-DebugToolbar's instance
debug_toolbar = DebugToolbarExtension()

# Create the Flask-Cache's instance
cache = Cache()

# Create the Flask-Admin's instance
flask_admin = Admin()

# Create the Flask-Mail's instance
mail = Mail()

# Create the Flask-Assets's instance
assets_env = Environment()
Example #9
0
from celery.schedules import crontab
from flask.ext.celery import Celery

CELERYBEAT_SCHEDULE = {
    # executes every night at 4:15
    'every-night': {
        'task': 'user.checkaccounts',
        'schedule': crontab(hour=4, minute=20)
    }
}

celery = Celery(www)


@celery.task(name='user.checkaccounts')
def checkaccounts():
    # do something
    pass
Example #10
0
    #email server config
    MAIL_SERVER="smtp.gmail.com",
    MAIL_PORT="587",
    MAIL_USE_TLS=True,
    MAIL_USE_SSL=False,
    MAIL_USERNAME="******",
    MAIL_PASSWORD="******",
    MAIL_FAIL_SILENTLY=False)
#setup jinja2 fragment caching
app.jinja_env.fragment_cache = RedisCache(host="127.0.0.1",
                                          default_timeout=86000)
app.jinja_env.add_extension(FragmentCacheExtension)

#connecting to celery
Celery(app)

#connect to mongohq
db.init_app(app)

#enabling markdown
Markdown(app)

#configuring flask-login
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = "other.login_required"
login_manager.session_protection


@login_manager.user_loader