Changeset View
Changeset View
Standalone View
Standalone View
swh/search/api/server.py
Show All 10 Lines | |||||
from swh.core.api import RPCServerApp | from swh.core.api import RPCServerApp | ||||
from swh.core.api import encode_data_server as encode_data | from swh.core.api import encode_data_server as encode_data | ||||
from swh.core.api import error_handler | from swh.core.api import error_handler | ||||
from swh.search.metrics import timed | from swh.search.metrics import timed | ||||
from .. import get_search | from .. import get_search | ||||
from ..interface import SearchInterface | from ..interface import SearchInterface | ||||
logger = logging.getLogger(__name__) | |||||
def _get_search(): | def _get_search(): | ||||
global search | global search | ||||
if not search: | if not search: | ||||
search = get_search(**app.config["search"]) | search = get_search(**app.config["search"]) | ||||
return search | return search | ||||
Show All 9 Lines | |||||
@app.route("/") | @app.route("/") | ||||
@timed | @timed | ||||
def index(): | def index(): | ||||
return "SWH Search API server" | return "SWH Search API server" | ||||
@app.before_first_request | |||||
def initialized_index(): | |||||
search = _get_search() | |||||
logger.error("Initializing indexes with configuration: ", search.origin_config) | |||||
search.initialize() | |||||
api_cfg = None | api_cfg = None | ||||
def load_and_check_config(config_file: str) -> Dict[str, Any]: | def load_and_check_config(config_file: str) -> Dict[str, Any]: | ||||
"""Check the minimal configuration is set to run the api or raise an | """Check the minimal configuration is set to run the api or raise an | ||||
error explanation. | error explanation. | ||||
Args: | Args: | ||||
Show All 40 Lines |