from flask.ext.script import Manager, Shell, Server from flask.ext.security.script import CreateUserCommand, AddRoleCommand, RemoveRoleCommand,ActivateUserCommand, DeactivateUserCommand from script import InstallCommand, ResetUserCommand from nyna import create_app from settings import DevConfig, ProdConfig #local settings should be ignored by git try: from local_settings import LocalConfig except ImportError: LocalConfig = None # if os.environ.get("ENFERNO_ENV") == 'prod': app = create_app(ProdConfig) # elif LocalConfig : # app = create_app(LocalConfig) # else: # app = create_app(DevConfig) manager = Manager(app) def _make_context(): """Return context dict for a shell session so you can access app default. """ return {'app': app}
from celery import Celery from celery.task import task, periodic_task from settings import Config def make_celery(app): celery = Celery(app.import_name, broker=Config.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 from nyna import create_app app = create_app(Config()) celery = make_celery(app) @task def test(): print session