Skip to content

Commit

Permalink
feature: New Mongo datalayer
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLark86 committed Jun 18, 2024
1 parent 84796a9 commit b5dc464
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 4 deletions.
2 changes: 0 additions & 2 deletions superdesk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from eve.methods.common import document_link # noqa
from werkzeug.exceptions import HTTPException

from .core.app import SuperdeskAsyncApp
from .eve_backend import EveBackend
from .datalayer import SuperdeskDataLayer # noqa
from .services import BaseService as Service # noqa
Expand All @@ -48,7 +47,6 @@
default_session_preferences: Dict[str, Any] = dict()
logger = logging_lib.getLogger(__name__)
app: Optional[eve.Eve] = None
async_app: Optional[SuperdeskAsyncApp] = None


class UserPreference(NamedTuple):
Expand Down
24 changes: 24 additions & 0 deletions superdesk/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ class SuperdeskAsyncApp:
#: A class instance that adheres to the WSGI protocol
wsgi: WSGIApp

#: MongoResources instance used to manage mongo config, clients and resources
mongo: "MongoResources"

def __init__(self, wsgi: WSGIApp):
self._running = False
self._imported_modules = {}
self.wsgi = wsgi
self.mongo = MongoResources(self)

@property
def running(self) -> bool:
Expand Down Expand Up @@ -75,5 +79,25 @@ def start(self):
self._load_modules(self.wsgi.config.get("MODULES", []))
self._running = True

def stop(self):
"""Stops the app
This tells :attr:`MongoResources to stop <superdesk.core.mongo.MongoResources.stop>`, clears imported modules
and sets :attr:`running <superdesk.core.app.SuperdeskAsyncApp.running>` to False
"""

self.mongo.stop()
self._imported_modules.clear()
self._running = False


def get_current_app() -> SuperdeskAsyncApp:
"""Retrieve the current app instance"""

from flask import current_app

return current_app.async_app


from .module import Module # noqa: E402
from .mongo import MongoResources # noqa: E402
Loading

0 comments on commit b5dc464

Please sign in to comment.