From 8dc1bc5ce891f9bd9034170cc4f5a6181b693645 Mon Sep 17 00:00:00 2001 From: MarkLark86 Date: Tue, 3 Oct 2023 00:49:43 +1100 Subject: [PATCH] [CPCN-326] improve(api): Use separate process for push celery worker (#132) * [CPCN-326] improve(api): Move push api/worker to separate processes * fix mgmt_api/products (due to changes in https://github.com/superdesk/newsroom-core/pull/578) * fix(behave): Add cache_type to config * config(fireq): Enable separate upstream for push endpoints * Revert "config(fireq): Enable separate upstream for push endpoints" This reverts commit 719faffa4c80fff8c7ebd411362f4ce1fb329fe5. * Remove `push` endpoints process * improve(web wsgi): Use gunicorn_config similar to Superdesks --- server/Procfile | 5 +++-- server/cp/mgmt_api/products.py | 2 +- server/features/environment.py | 2 ++ server/gunicorn_config.py | 12 ++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 server/gunicorn_config.py diff --git a/server/Procfile b/server/Procfile index acdf416..eb86eba 100644 --- a/server/Procfile +++ b/server/Procfile @@ -1,6 +1,7 @@ -web: gunicorn -b 0.0.0.0:$PORT -w 3 newsroom.web.app:app +web: gunicorn -c gunicorn_config.py newsroom.web.app:app websocket: python -m newsroom.web.ws -worker: celery -A newsroom.web.worker.celery worker +worker: celery -A newsroom.web.worker.celery worker -X "${SUPERDESK_CELERY_PREFIX}newsroom.push" +push_worker: celery -A newsroom.web.worker.celery worker -Q "${SUPERDESK_CELERY_PREFIX}newsroom.push" beat: celery -A newsroom.web.worker.celery beat newsapi: gunicorn -b "0.0.0.0:${APIPORT:-$PORT}" -w 3 newsroom.news_api.app:app mgmtapi: gunicorn -b "0.0.0.0:${MGMTPORT:-$PORT}" -w 3 cp.mgmt_api.app:app diff --git a/server/cp/mgmt_api/products.py b/server/cp/mgmt_api/products.py index 37cea42..9864756 100644 --- a/server/cp/mgmt_api/products.py +++ b/server/cp/mgmt_api/products.py @@ -1,4 +1,4 @@ -from newsroom.products import ProductsResource, ProductsService +from newsroom.products.products import ProductsResource, ProductsService import superdesk diff --git a/server/features/environment.py b/server/features/environment.py index d075e5e..f8e2ea1 100644 --- a/server/features/environment.py +++ b/server/features/environment.py @@ -21,6 +21,7 @@ def before_all(context): 'INSTALLED_APPS': [], 'ELASTICSEARCH_FORCE_REFRESH': True, 'MGMT_API_ENABLED': True, + 'CACHE_TYPE': "null", } setup_before_all(context, config, app_factory=get_app) @@ -33,6 +34,7 @@ def before_scenario(context, scenario): 'ELASTICSEARCH_FORCE_REFRESH': True, 'MGMT_API_ENABLED': True, 'AUTH_SERVER_SHARED_SECRET': 'test-secret', + 'CACHE_TYPE': "null", } setup_before_scenario(context, scenario, config, app_factory=get_app) diff --git a/server/gunicorn_config.py b/server/gunicorn_config.py new file mode 100644 index 0000000..a67084b --- /dev/null +++ b/server/gunicorn_config.py @@ -0,0 +1,12 @@ +import os +import multiprocessing + +port = os.environ.get("PORT", "5000") +bind = f"0.0.0.0:{port}" +workers = int(os.environ.get("WEB_CONCURRENCY", multiprocessing.cpu_count() + 1)) + +accesslog = "-" +access_log_format = "%(m)s %(U)s status=%(s)s time=%(T)ss size=%(B)sb" + +reload = 'SUPERDESK_RELOAD' in os.environ +timeout = int(os.environ.get('WEB_TIMEOUT', 30))