From f33f882e2f153531c8b5546e49c1c2554886dd95 Mon Sep 17 00:00:00 2001 From: Luyao Huang Date: Wed, 3 Apr 2019 14:04:21 +0800 Subject: [PATCH] Add flask-sse to make metadash support server side event Signed-off-by: Luyao Huang --- Pipfile | 2 ++ deploy/gunicorn.py | 4 +++- metadash/__init__.py | 5 +++++ metadash/build/config/index.js | 3 +++ metadash/settings.py | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index 8ee6093..8e429d3 100644 --- a/Pipfile +++ b/Pipfile @@ -31,12 +31,14 @@ requests = "*" coloredlogs = "*" "psycopg2-binary" = "*" gunicorn = "*" +gevent = "*" Flask = "*" Flask-Migrate = "*" Flask-RESTful = "*" Flask-Script = "*" Flask-Session = "*" Flask-SQLAlchemy = "*" +Flask-SSE = "*" Flask-WTF = "*" SQLAlchemy = "*" Sphinx = "*" diff --git a/deploy/gunicorn.py b/deploy/gunicorn.py index 6c3229b..d6f6055 100644 --- a/deploy/gunicorn.py +++ b/deploy/gunicorn.py @@ -1,6 +1,8 @@ import multiprocessing bind = '0.0.0.0:8080' -multiprocessing.cpu_count() * 2 + 1 +workers = multiprocessing.cpu_count() * 2 + 1 +worker_class = 'gevent' +worker_connections = 200 timeout = 300 accesslog = '-' diff --git a/metadash/__init__.py b/metadash/__init__.py index f487bb1..9f3c81d 100644 --- a/metadash/__init__.py +++ b/metadash/__init__.py @@ -83,6 +83,11 @@ def setup_logger(): app.register_blueprint(metadata, url_prefix="/api") +# Register SSE +from flask_sse import sse +app.register_blueprint(sse, url_prefix='/stream') + + @app.route('/', defaults={"path": ""}) @app.route('/') def index(path): diff --git a/metadash/build/config/index.js b/metadash/build/config/index.js index 3a376cb..46bd6a9 100644 --- a/metadash/build/config/index.js +++ b/metadash/build/config/index.js @@ -31,6 +31,9 @@ module.exports = { '/api': { target: 'http://localhost:5000' // TODO: should be changable }, + '/stream': { + target: 'http://localhost:5000' // TODO: should be changable + }, '/docs': { target: 'http://localhost:5000' // TODO: should be changable } diff --git a/metadash/settings.py b/metadash/settings.py index 450efec..fd46463 100644 --- a/metadash/settings.py +++ b/metadash/settings.py @@ -116,8 +116,10 @@ def initialize(settings): } settings.CELERY_BROKER_URL = settings.REDIS_URI settings.CELERY_RESULT_BACKEND = settings.REDIS_URI + settings.REDIS_URL = settings.REDIS_URI else: settings.CACHE_DEFAULT_BACKEND = "dogpile.cache.memory" settings.CACHE_ARGUEMENTS = {} settings.CELERY_BROKER_URL = '' settings.CELERY_RESULT_BACKEND = '' + settings.REDIS_URL = ''