Skip to content

Commit

Permalink
Merge pull request #171 from devketanpro/enable_async
Browse files Browse the repository at this point in the history
Enable async
  • Loading branch information
devketanpro authored Dec 20, 2024
2 parents 8e2d9a5 + a326339 commit 01a8028
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 160 deletions.
4 changes: 2 additions & 2 deletions server/Procfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
web: gunicorn -c gunicorn_config.py newsroom.web.app:app
web: hypercorn -c file:hypercorn_config.py newsroom.web.app:app
websocket: python -m newsroom.web.ws
worker: celery -A newsroom.web.worker.celery worker
beat: celery -A newsroom.web.worker.celery beat
newsapi: gunicorn -b "0.0.0.0:${APIPORT:-$PORT}" -w 3 newsroom.news_api.app:app
newsapi: hypercorn -b "0.0.0.0:${APIPORT:-$PORT}" -w 3 newsroom.news_api.app:app
3 changes: 3 additions & 0 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from newsroom.web.factory import get_app

app = get_app()
38 changes: 19 additions & 19 deletions server/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ def get_app(*args, **kwargs):

def before_all(context):
config = {
'BEHAVE': True,
'CORE_APPS': CORE_APPS,
'INSTALLED_APPS': [],
'ELASTICSEARCH_FORCE_REFRESH': True,
'NEWS_API_ENABLED': True,
'NEWS_API_TIME_LIMIT_DAYS': 100,
'NEWS_API_BEHAVE_TESTS': True,
'CACHE_TYPE': "null",
"BEHAVE": True,
"CORE_APPS": CORE_APPS,
"INSTALLED_APPS": [],
"ELASTICSEARCH_FORCE_REFRESH": True,
"NEWS_API_ENABLED": True,
"NEWS_API_TIME_LIMIT_DAYS": 100,
"NEWS_API_BEHAVE_TESTS": True,
"CACHE_TYPE": "null",
}
setup_before_all(context, config, app_factory=get_app)


def before_scenario(context, scenario):
config = {
'BEHAVE': True,
'CORE_APPS': CORE_APPS,
'INSTALLED_APPS': [],
'ELASTICSEARCH_FORCE_REFRESH': True,
'NEWS_API_ENABLED': True,
'NEWS_API_TIME_LIMIT_DAYS': 100,
'NEWS_API_BEHAVE_TESTS': True,
'CACHE_TYPE': "null",
"BEHAVE": True,
"CORE_APPS": CORE_APPS,
"INSTALLED_APPS": [],
"ELASTICSEARCH_FORCE_REFRESH": True,
"NEWS_API_ENABLED": True,
"NEWS_API_TIME_LIMIT_DAYS": 100,
"NEWS_API_BEHAVE_TESTS": True,
"CACHE_TYPE": "null",
}

if 'rate_limit' in scenario.tags:
config['RATE_LIMIT_PERIOD'] = 300 # 5 minutes
config['RATE_LIMIT_REQUESTS'] = 2
if "rate_limit" in scenario.tags:
config["RATE_LIMIT_PERIOD"] = 300 # 5 minutes
config["RATE_LIMIT_REQUESTS"] = 2

setup_before_scenario(context, scenario, config, app_factory=get_app)
2 changes: 1 addition & 1 deletion server/features/steps/steps.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from newsroom.tests.steps import * # noqa
from newsroom.tests.steps import * # noqa
12 changes: 0 additions & 12 deletions server/gunicorn_config.py

This file was deleted.

10 changes: 10 additions & 0 deletions server/hypercorn_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

bind = "0.0.0.0:%s" % os.environ.get("PORT", "5000")
workers = int(os.environ.get("WEB_CONCURRENCY", 3))
timeout = int(os.environ.get("WEB_TIMEOUT", 30))

accesslog = "-"
access_log_format = "%(m)s %(U)s status=%(s)s time=%(T)ss size=%(B)sb"

use_reloader = "NEWSROOM_RELOAD" in os.environ
5 changes: 2 additions & 3 deletions server/manage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from newsroom.commands import * # noqa
from newsroom.commands.manager import manager
from quart.cli import main


if __name__ == "__main__":
manager.run()
main()
9 changes: 5 additions & 4 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --resolver=backtracking requirements.in
# pip-compile requirements.in
#
aiofiles==24.1.0
# via
Expand Down Expand Up @@ -37,7 +37,7 @@ async-timeout==5.0.1
# redis
attrs==24.3.0
# via aiohttp
authlib==1.3.2
authlib==1.4.0
# via superdesk-core
babel==2.16.0
# via quart-babel
Expand All @@ -53,9 +53,9 @@ blinker==1.8.2
# quart
# sentry-sdk
# superdesk-core
boto3==1.35.84
boto3==1.35.85
# via superdesk-core
botocore==1.35.84
botocore==1.35.85
# via
# boto3
# s3transfer
Expand Down Expand Up @@ -475,6 +475,7 @@ wtforms[email]==3.1.2
# via
# newsroom-core
# quart-wtforms
# wtforms
xhtml2pdf==0.2.16
# via newsroom-core
xmlsec==1.3.14
Expand Down
2 changes: 1 addition & 1 deletion server/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import pathlib

from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
from newsroom.types import AuthProviderType
from newsroom.web.default_settings import (
ELASTICSEARCH_SETTINGS,
Expand Down
2 changes: 1 addition & 1 deletion server/settings_newsapi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from superdesk.default_settings import env, strtobool # noqa
from superdesk.default_settings import env, strtobool # noqa
from newsroom.news_api.default_settings import CORE_APPS, INSTALLED_APPS, BLUEPRINTS


Expand Down
2 changes: 1 addition & 1 deletion server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


setup(
name='Newsroom App STT',
name="Newsroom App STT",
packages=find_packages(),
)
7 changes: 4 additions & 3 deletions server/stt/external_links.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

def init_app(app):
app.sidenav('Kuvakauppa', url='http://kuvakauppa.lehtikuva.fi', icon='photo', group=8)
app.sidenav('STT Info', url='https://www.sttinfo.fi', icon='info', group=8)
app.sidenav(
"Kuvakauppa", url="http://kuvakauppa.lehtikuva.fi", icon="photo", group=8
)
app.sidenav("STT Info", url="https://www.sttinfo.fi", icon="info", group=8)
82 changes: 46 additions & 36 deletions server/stt/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,63 @@
def get_previous_version(app, guid, version):
for i in range(int(version) - 1, 1, -1):
id = "{}:{}".format(guid, i)
original = app.data.find_one('items', req=None, _id=id)
original = app.data.find_one("items", req=None, _id=id)
if original:
return original

return app.data.find_one('items', req=None, _id=guid)
return app.data.find_one("items", req=None, _id=guid)


def on_publish_item(app, item, is_new, **kwargs):
"""Populate stt department and version fields."""
if item.get('subject'):
for subject in item['subject']:
if subject.get('scheme', '') in STT_FIELDS:
item[subject['scheme']] = subject.get('name', subject.get('code'))
item['subject'] = [subject for subject in item['subject'] if subject.get('scheme') != 'sttdone1']
if item.get("subject"):
for subject in item["subject"]:
if subject.get("scheme", "") in STT_FIELDS:
item[subject["scheme"]] = subject.get("name", subject.get("code"))
item["subject"] = [
subject
for subject in item["subject"]
if subject.get("scheme") != "sttdone1"
]

# add private note to ednote
if item.get('extra', {}).get('sttnote_private'):
if item.get('ednote'):
item['ednote'] = '{}\n{}'.format(item['ednote'], item['extra']['sttnote_private'])
if item.get("extra", {}).get("sttnote_private"):
if item.get("ednote"):
item["ednote"] = "{}\n{}".format(
item["ednote"], item["extra"]["sttnote_private"]
)
else:
item['ednote'] = item['extra']['sttnote_private']
item["ednote"] = item["extra"]["sttnote_private"]

# set versioncreated for archive items
if item.get('firstpublished') and is_new:
if isinstance(item.get('firstpublished'), str):
firstpublished = parse_date(item['firstpublished'])
if item.get("firstpublished") and is_new:
if isinstance(item.get("firstpublished"), str):
firstpublished = parse_date(item["firstpublished"])
else:
firstpublished = item['firstpublished']
firstpublished = item["firstpublished"]

if firstpublished < item['versioncreated']:
item['versioncreated'] = firstpublished
if firstpublished < item["versioncreated"]:
item["versioncreated"] = firstpublished

# link the previous versions and update the id of the story
if not is_new and 'evolvedfrom' not in item:
original = get_previous_version(app, item['guid'], item['version'])
if not is_new and "evolvedfrom" not in item:
original = get_previous_version(app, item["guid"], item["version"])

if original:
if original.get('version') == item['version']:
if original.get("version") == item["version"]:
# the same version of the story been sent again so no need to create new version
return

service = superdesk.get_resource_service('content_api')
new_id = '{}:{}'.format(item['guid'], item['version'])
service.system_update(original['_id'], {'nextversion': new_id}, original)
item['guid'] = new_id
item['ancestors'] = copy(original.get('ancestors', []))
item['ancestors'].append(original['_id'])
item['bookmarks'] = original.get('bookmarks', [])
service = superdesk.get_resource_service("content_api")
new_id = "{}:{}".format(item["guid"], item["version"])
service.system_update(original["_id"], {"nextversion": new_id}, original)
item["guid"] = new_id
item["ancestors"] = copy(original.get("ancestors", []))
item["ancestors"].append(original["_id"])
item["bookmarks"] = original.get("bookmarks", [])

# dump abstract
for field in ('description_html', 'description_text'):
for field in ("description_html", "description_text"):
item.pop(field, None)


Expand All @@ -72,11 +78,15 @@ def init_app(app):

# add extra fields to elastic mapping
for field in STT_ROOT_FIELDS:
for resource in ('items', 'content_api'):
app.config['DOMAIN'][resource]['schema'].update({
field: {'type': 'string', 'mapping': not_analyzed},
})

app.config['SOURCES'][resource]['projection'].update({
field: 1,
})
for resource in ("items", "content_api"):
app.config["DOMAIN"][resource]["schema"].update(
{
field: {"type": "string", "mapping": not_analyzed},
}
)

app.config["SOURCES"][resource]["projection"].update(
{
field: 1,
}
)
1 change: 0 additions & 1 deletion server/stt/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from newsroom.signals import publish_planning


Expand Down
2 changes: 1 addition & 1 deletion server/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
init_agenda_items,
init_auth,
setup_user_company,
init_company
init_company,
)
1 change: 0 additions & 1 deletion server/tests/test_signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from stt.signals import publish_planning, set_planning_all_day


Expand Down
Loading

0 comments on commit 01a8028

Please sign in to comment.