Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/cookers/base.py
# Copyright (C) 2016-2018 The Software Heritage developers | # Copyright (C) 2016-2018 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 abc | import abc | ||||
import io | import io | ||||
import logging | import logging | ||||
from typing import Optional | from typing import Optional | ||||
from psycopg2.extensions import QueryCanceledError | from psycopg2.extensions import QueryCanceledError | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.model.model import Sha1Git | |||||
from swh.storage.interface import StorageInterface | |||||
MAX_BUNDLE_SIZE = 2 ** 29 # 512 MiB | MAX_BUNDLE_SIZE = 2 ** 29 # 512 MiB | ||||
DEFAULT_CONFIG_PATH = "vault/cooker" | DEFAULT_CONFIG_PATH = "vault/cooker" | ||||
DEFAULT_CONFIG = { | DEFAULT_CONFIG = { | ||||
"max_bundle_size": ("int", MAX_BUNDLE_SIZE), | "max_bundle_size": ("int", MAX_BUNDLE_SIZE), | ||||
} | } | ||||
Show All 35 Lines | class BaseVaultCooker(metaclass=abc.ABCMeta): | ||||
- CACHE_TYPE_KEY: key to use for the bundle to reference in cache | - CACHE_TYPE_KEY: key to use for the bundle to reference in cache | ||||
- def cook(): cook the object into a bundle | - def cook(): cook the object into a bundle | ||||
""" | """ | ||||
CACHE_TYPE_KEY = None # type: Optional[str] | CACHE_TYPE_KEY = None # type: Optional[str] | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
obj_type, | obj_type: str, | ||||
obj_id, | obj_id: Sha1Git, | ||||
backend, | backend, | ||||
storage, | storage: StorageInterface, | ||||
graph=None, | graph=None, | ||||
objstorage=None, | objstorage=None, | ||||
max_bundle_size=MAX_BUNDLE_SIZE, | max_bundle_size: int = MAX_BUNDLE_SIZE, | ||||
): | ): | ||||
"""Initialize the cooker. | """Initialize the cooker. | ||||
The type of the object represented by the id depends on the | The type of the object represented by the id depends on the | ||||
concrete class. Very likely, each type of bundle will have its | concrete class. Very likely, each type of bundle will have its | ||||
own cooker class. | own cooker class. | ||||
Args: | Args: | ||||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |