def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD')) mail_handler = SMTPHandler(app.config.get('MAIL_SERVER'), app.config.get('MAIL_FROM'), app.config.get('MAIL_ADMINS'), '[%s] Crash report' % app_name, credentials=credentials, secure=()) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if 'postgres' not in app.config.get('SQLALCHEMY_DATABASE_URI', ''): raise RuntimeError("aleph database must be PostgreSQL!") queues = ( Queue(WORKER_QUEUE, routing_key=WORKER_ROUTING_KEY), Queue(USER_QUEUE, routing_key=USER_ROUTING_KEY), ) # celery.conf.update(app.config) celery.conf.update( imports=('aleph.queues'), broker_url=app.config['CELERY_BROKER_URL'], task_always_eager=app.config['CELERY_ALWAYS_EAGER'], task_eager_propagates=True, task_ignore_result=True, result_persistent=False, task_queues=queues, task_default_queue=WORKER_QUEUE, task_default_routing_key=WORKER_ROUTING_KEY, # ultra-high time limit to shoot hung tasks: task_time_limit=3600 * 3, worker_max_tasks_per_child=200, worker_disable_rate_limits=True, beat_schedule=app.config['CELERYBEAT_SCHEDULE'], ) migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR')) configure_oauth(app) mail.init_app(app) db.init_app(app) # This executes all registered init-time plugins so that other # applications can register their behaviour. for plugin in get_init(): plugin(app=app) return app
def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) if config.get('TESTING'): app.config.from_envvar('ALEPH_TEST_SETTINGS', silent=True) else: app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD')) mail_handler = SMTPHandler(app.config.get('MAIL_SERVER'), app.config.get('MAIL_FROM'), app.config.get('MAIL_ADMINS'), '[%s] Crash report' % app_name, credentials=credentials, secure=()) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if 'postgres' not in app.config.get('SQLALCHEMY_DATABASE_URI', ''): raise RuntimeError("aleph database must be PostgreSQL!") app.config['CELERY_DEFAULT_QUEUE'] = WORKER_QUEUE app.config['CELERY_DEFAULT_ROUTING_KEY'] = WORKER_ROUTING_KEY app.config['CELERY_QUEUES'] = ( Queue(WORKER_QUEUE, routing_key=WORKER_ROUTING_KEY), Queue(USER_QUEUE, routing_key=USER_ROUTING_KEY), ) celery.conf.update(app.config) celery.conf.update({ 'BROKER_URL': app.config['CELERY_BROKER_URL'] }) migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR')) oauth.init_app(app) mail.init_app(app) db.init_app(app) assets.init_app(app) # This executes all registered init-time plugins so that other # applications can register their behaviour. for plugin in get_init(): plugin(app=app) return app
def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) if config.get('TESTING'): app.config.from_envvar('ALEPH_TEST_SETTINGS', silent=True) else: app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD')) mail_handler = SMTPHandler(app.config.get('MAIL_SERVER'), app.config.get('MAIL_FROM'), app.config.get('MAIL_ADMINS'), '[%s] Crash report' % app_name, credentials=credentials, secure=()) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if 'postgres' not in app.config.get('SQLALCHEMY_DATABASE_URI', ''): raise RuntimeError("aleph database must be PostgreSQL!") queue_name = app_name + '_q' app.config['CELERY_DEFAULT_QUEUE'] = queue_name app.config['CELERY_QUEUES'] = ( Queue(queue_name, Exchange(queue_name), routing_key=queue_name), ) celery.conf.update(app.config) celery.conf.update({ 'BROKER_URL': app.config['CELERY_BROKER_URL'] }) migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR')) oauth.init_app(app) mail.init_app(app) db.init_app(app) assets.init_app(app) # This executes all registered init-time plugins so that other # applications can register their behaviour. for name, plugin in get_init().items(): plugin(app=app) return app
def create_app(config={}): app = Flask('aleph') app.config.from_object(default_settings) app.config.from_envvar('ALEPH_SETTINGS', silent=True) app.config.update(config) app_name = app.config.get('APP_NAME') if app.config.get("TESTING"): # The testing configuration is inferred from the production # settings, but it can only be derived after the config files # have actually been evaluated. database_uri = app.config.get('SQLALCHEMY_DATABASE_URI') app.config['SQLALCHEMY_DATABASE_URI'] = database_uri + '_test' es_index = app.config.get('ELASTICSEARCH_INDEX', app.config.get('APP_NAME')) app.config['ELASTICSEARCH_INDEX'] = es_index + '_test' if not app.debug and app.config.get('MAIL_ADMINS'): credentials = (app.config.get('MAIL_USERNAME'), app.config.get('MAIL_PASSWORD')) mail_handler = SMTPHandler(app.config.get('MAIL_SERVER'), app.config.get('MAIL_FROM'), app.config.get('MAIL_ADMINS'), '[%s] Crash report' % app_name, credentials=credentials, secure=()) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if 'postgres' not in app.config.get('SQLALCHEMY_DATABASE_URI', ''): raise RuntimeError("aleph database must be PostgreSQL!") queues = ( Queue(WORKER_QUEUE, routing_key=WORKER_ROUTING_KEY), Queue(USER_QUEUE, routing_key=USER_ROUTING_KEY), ) celery.conf.update( imports=('aleph.queues'), broker_url=app.config['CELERY_BROKER_URL'], task_always_eager=app.config['CELERY_ALWAYS_EAGER'], task_eager_propagates=True, task_ignore_result=True, result_persistent=False, task_queues=queues, task_default_queue=WORKER_QUEUE, task_default_routing_key=WORKER_ROUTING_KEY, # ultra-high time limit to shoot hung tasks: task_time_limit=3600 * 3, worker_max_tasks_per_child=500, worker_disable_rate_limits=True, # worker_hijack_root_logger=False, beat_schedule=app.config['CELERYBEAT_SCHEDULE'], ) celery.conf.update(app.config.get('CELERY', {})) migrate.init_app(app, db, directory=app.config.get('ALEMBIC_DIR')) configure_oauth(app) mail.init_app(app) db.init_app(app) try: ldap.init_app(app) except LDAPException as error: log.info(error) # This executes all registered init-time plugins so that other # applications can register their behaviour. for plugin in get_init(): plugin(app=app) return app
def create_app(config={}): app = Flask('aleph') app.config.from_object(settings) app.config.update(config) if 'postgres' not in settings.DATABASE_URI: raise RuntimeError("aleph database must be PostgreSQL!") app.config.update({ 'SQLALCHEMY_DATABASE_URI': settings.DATABASE_URI }) # if settings.MAIL_SERVER and settings.ADMINS: # credentials = (settings.MAIL_USERNAME, # settings.MAIL_PASSWORD) # subject = '[%s] Crash report' % settings.APP_TITLE # mail_handler = SMTPHandler(settings.MAIL_SERVER, # settings.MAIL_FROM, # settings.ADMINS, # subject, # credentials=credentials, # secure=()) # mail_handler.setLevel(logging.ERROR) # app.logger.addHandler(mail_handler) queues = ( Queue(WORKER_QUEUE, routing_key=WORKER_ROUTING_KEY), Queue(USER_QUEUE, routing_key=USER_ROUTING_KEY), ) celery.conf.update( imports=('aleph.queues'), broker_url=settings.BROKER_URI, task_always_eager=settings.EAGER, task_eager_propagates=True, task_ignore_result=True, result_persistent=False, task_queues=queues, task_default_queue=WORKER_QUEUE, task_default_routing_key=WORKER_ROUTING_KEY, worker_max_tasks_per_child=500, worker_disable_rate_limits=True, beat_schedule={ 'alert-every-night': { 'task': 'aleph.logic.alerts.check_alerts', 'schedule': crontab(hour=1, minute=30) } }, ) migrate.init_app(app, db, directory=settings.ALEMBIC_DIR) configure_oauth(app) mail.init_app(app) db.init_app(app) CORS(app, origins=settings.CORS_ORIGINS) # Enable raven to submit issues to sentry if a DSN is defined. This will # report errors from Flask and Celery operation modes to Sentry. if settings.SENTRY_DSN: sentry.init_app(app, dsn=settings.SENTRY_DSN, logging=True, level=logging.ERROR) register_logger_signal(sentry.client) register_signal(sentry.client, ignore_expected=True) # This executes all registered init-time plugins so that other # applications can register their behaviour. for plugin in get_init(): plugin(app=app) return app