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) logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) app.run(host='0.0.0.0', port=int(OPTIONS['--port']))
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', '--without-gossip' ] #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 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()
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)