Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/api/server.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
import logging | import logging | ||||
from swh.core import config | from swh.core import config | ||||
from swh.storage import get_storage as get_swhstorage | from swh.storage import get_storage as get_swhstorage | ||||
from swh.core.api import (RPCServerApp, | from swh.core.api import (RPCServerApp, | ||||
error_handler, | error_handler, | ||||
encode_data_server as encode_data) | encode_data_server as encode_data) | ||||
from ..storage import Storage | from ..interface import StorageInterface | ||||
from ..metrics import timed | from ..metrics import timed | ||||
def get_storage(): | def get_storage(): | ||||
global storage | global storage | ||||
if not storage: | if not storage: | ||||
storage = get_swhstorage(**app.config['storage']) | storage = get_swhstorage(**app.config['storage']) | ||||
return storage | return storage | ||||
app = RPCServerApp(__name__, | app = RPCServerApp(__name__, | ||||
backend_class=Storage, | backend_class=StorageInterface, | ||||
backend_factory=get_storage) | backend_factory=get_storage) | ||||
storage = None | storage = None | ||||
@app.errorhandler(Exception) | @app.errorhandler(Exception) | ||||
def my_error_handler(exception): | def my_error_handler(exception): | ||||
return error_handler(exception, encode_data) | return error_handler(exception, encode_data) | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |