def create_app():
    initialize()
    # App initialization code goes here
    app = Flask(__name__)

    common_app_setup(app)

    # Handle user sessions
    app.before_request(process_user_from_session)

    # Register csrf everywhere
    register_csrf(app, exclude_url_pattern=CSRF_EXCLUDE_PATTERN)

    # Register blueprints/views
    app.register_blueprint(api, url_prefix='/api')
    app.register_blueprint(web)

    app.add_url_rule('/api/graphql', view_func=create_graphql_view())

    return app
Exemple #2
0
def create_grpc_server(address='[::]:50051', num_workers=DEFAULT_NUM_WORKERS):
    app.initialize()

    if config.SCOUT_KEY:  # pragma: no cover
        scout_config = {
            'name':
            config.SCOUT_NAME,
            'key':
            config.SCOUT_KEY,
            'monitor':
            True,
            'core_agent_full_name':
            "scout_apm_core-v1.1.8-x86_64-unknown-linux-musl"
        }
        scout_apm.api.install(config=scout_config)

    default_interceptor = DefaultInterceptor()

    pool = futures.ThreadPoolExecutor(max_workers=num_workers)
    options = (
        ('grpc.keepalive_permit_without_calls', True),
        ('grpc.http2.max_pings_without_data', 0),
        ('grpc.http2.min_time_between_pings_ms', 1000),
        ('grpc.http2.min_ping_interval_without_data_ms', 1000),
        ('grpc.http2.max_ping_strikes', 0),
    )

    server = grpc.server(pool,
                         interceptors=(default_interceptor, ),
                         options=options)

    alvinchow_backend_pb2_grpc.add_AlvinChowServiceServicer_to_server(
        AlvinChowServiceServicer(), server)
    server.add_insecure_port(address)

    initialize_sentry()

    return server
Exemple #3
0
#!/usr/bin/env python

from alvinchow_backend import app
from alvinchow_backend.app import config  # noqa
from alvinchow_backend.db import get_session
from alvinchow_backend.db.models import *  # noqa
from alvinchow_backend.lib.logger import get_logger
from alvinchow_backend.lib.redis import get_redis_connection  # noqa

app.initialize()

logger = get_logger()
session = get_session()
Exemple #4
0
"""
Celery worker entry point
"""
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
import scout_apm.api
import scout_apm.celery

from alvinchow_backend.app.celery import app  # noqa, this module needs "app"
from alvinchow_backend.app import config, initialize
from alvinchow_backend.app.monitoring import initialize_sentry

initialize()
initialize_sentry(celery=True)

if config.SENTRY_DSN:  # pragma: no cover
    sentry_sdk.init(dsn=config.SENTRY_DSN, integrations=[CeleryIntegration()])

if config.SCOUT_KEY:  # pragma: no cover
    scout_apm.api.Config.set(
        key=config.SCOUT_KEY,
        name=config.SCOUT_NAME,
        monitor=True,
        full_name="scout_apm_core-v1.1.8-x86_64-unknown-linux-musl",
    )

    scout_apm.celery.install()
def test_app():
    app.initialize()
    assert initialization.is_initialized()
    app.initialize()