def celerybeat(): setup_logging('celerybeat') app = create_app(parse_options(), no_sql=True) Logging._setup = True celery_args = ['celery', 'beat', '-C', '--pidfile', OPTIONS['--pid'], '-s', OPTIONS['--schedule']] with app.app_context(): return celery_main(celery_args)
def celeryworker(): setup_logging('celeryworker{}'.format(OPTIONS['--name'])) app = create_app(parse_options(), no_sql=True) Logging._setup = True celery_args = ['celery', 'worker', '-n', OPTIONS['--name'], '-C', '--autoscale=10,1', '--without-gossip'] with app.app_context(): return celery_main(celery_args)
def celerydev(): setup_logging('celerydev') app = create_app(parse_options(), no_sql=True) Logging._setup = True # Disable Celery from setting up logging, already done in setup_logging(). celery_args = ['celery', 'worker', '-B', '-s', '/tmp/celery.db', '--concurrency=5'] with app.app_context(): return celery_main(celery_args)
def celerydev(): setup_logging('celerydev') app = create_app(parse_options(), no_sql=True) Logging._setup = True # Disable Celery from setting up logging, already done in setup_logging(). celery_args = [ 'celery', 'worker', '-B', '-s', '/tmp/celery.db', '--concurrency=5' ] with app.app_context(): return celery_main(celery_args)
def celeryworker(): setup_logging('celeryworker{}'.format(OPTIONS['--name'])) app = create_app(parse_options(), no_sql=True) Logging._setup = True celery_args = [ 'celery', 'worker', '-n', OPTIONS['--name'], '-C', '--autoscale=10,1', '--without-gossip' ] with app.app_context(): return celery_main(celery_args)
def celerybeat(): setup_logging('celerybeat') app = create_app(parse_options(), no_sql=True) Logging._setup = True celery_args = [ 'celery', 'beat', '-C', '--pidfile', OPTIONS['--pid'], '-s', OPTIONS['--schedule'] ] with app.app_context(): return celery_main(celery_args)
def create_all(): setup_logging('create_all') app = create_app(parse_options()) log = logging.getLogger(__name__) with app.app_context(): tables_before = set(db.engine.table_names()) db.create_all() tables_after = set(db.engine.table_names()) created_tables = tables_after - tables_before for table in created_tables: log.info('Created table: {}'.format(table))
def create_all(): setup_logging('create_all') app = create_app(parse_options()) log = logging.getLogger(__name__) with app.app_context(): tables_before = {t[0] for t in db.session.execute('SHOW TABLES')} db.create_all() tables_after = {t[0] for t in db.session.execute('SHOW TABLES')} created_tables = tables_after - tables_before for table in created_tables: log.info('Created table: {}'.format(table))
def tornadoserver(): setup_logging('tornadoserver') app = create_app(parse_options()) fsh_folder = app.blueprints['flask_statics_helper'].static_folder log_messages(app, OPTIONS['--port'], fsh_folder) # Setup the application. container = wsgi.WSGIContainer(app) application = web.Application([ (r'/static/flask_statics_helper/(.*)', web.StaticFileHandler, dict(path=fsh_folder)), (r'/(favicon\.ico)', web.StaticFileHandler, dict(path=app.static_folder)), (r'/static/(.*)', web.StaticFileHandler, dict(path=app.static_folder)), (r'.*', web.FallbackHandler, dict(fallback=container)) ]) # From http://maxburstein.com/blog/django-static-files-heroku/ http_server = httpserver.HTTPServer(application) http_server.bind(OPTIONS['--port']) # Start the server. http_server.start(0) # Forks multiple sub-processes ioloop.IOLoop.instance().start()
@pytest.fixture(autouse=True, scope='session') def create_all(): """Create all database tables.""" db.create_all() @pytest.fixture(scope='session') def alter_xmlrpc(request): """Replaces the ServerProxy class in the xmlrpclib library with a fake class. Class is restored after testing. """ old_method = xmlrpclib.ServerProxy xmlrpclib.ServerProxy = FakeServerProxy def func(value): FakeServerProxy.VALUE = value def fin(): xmlrpclib.ServerProxy = old_method request.addfinalizer(fin) return func # Initialize the application and sets the app context to avoid needing 'with app.app_context():'. # This must happen before any Celery tasks are imported automatically by py.test during test discovery. create_app(get_config('pypi_portal.config.Testing')).app_context().push()
def shell(): setup_logging('shell') app = create_app(parse_options()) app.app_context().push() Shell(make_context=lambda: dict(app=app, db=db)).run(no_ipython=False, no_bpython=False)
def devserver(): setup_logging('devserver') app = create_app(parse_options()) fsh_folder = app.blueprints['flask_statics_helper'].static_folder log_messages(app, OPTIONS['--port'], fsh_folder) app.run(host='0.0.0.0', port=int(OPTIONS['--port']))