Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/in_memory_backend.py
Show All 12 Lines | |||||
class InMemoryVaultBackend: | class InMemoryVaultBackend: | ||||
"""Stub vault backend, for use in the CLI.""" | """Stub vault backend, for use in the CLI.""" | ||||
def __init__(self): | def __init__(self): | ||||
self._cache = VaultCache(cls="memory") | self._cache = VaultCache(cls="memory") | ||||
def fetch(self, obj_type: str, obj_id: ObjectId) -> Optional[bytes]: | def fetch(self, bundle_type: str, obj_id: ObjectId) -> Optional[bytes]: | ||||
return self._cache.get(obj_type, hash_to_bytes(obj_id)) | return self._cache.get(bundle_type, hash_to_bytes(obj_id)) | ||||
def cook( | def cook( | ||||
self, obj_type: str, obj_id: ObjectId, email: Optional[str] = None | self, bundle_type: str, obj_id: ObjectId, email: Optional[str] = None | ||||
) -> Dict[str, Any]: | ) -> Dict[str, Any]: | ||||
raise NotImplementedError("InMemoryVaultBackend.cook()") | raise NotImplementedError("InMemoryVaultBackend.cook()") | ||||
def progress(self, obj_type: str, obj_id: ObjectId): | def progress(self, bundle_type: str, obj_id: ObjectId): | ||||
raise NotImplementedError("InMemoryVaultBackend.progress()") | raise NotImplementedError("InMemoryVaultBackend.progress()") | ||||
# Cookers endpoints | # Cookers endpoints | ||||
def set_progress(self, obj_type: str, obj_id: ObjectId, progress: str) -> None: | def set_progress(self, bundle_type: str, obj_id: ObjectId, progress: str) -> None: | ||||
pass | pass | ||||
def set_status(self, obj_type: str, obj_id: ObjectId, status: str) -> None: | def set_status(self, bundle_type: str, obj_id: ObjectId, status: str) -> None: | ||||
pass | pass | ||||
def put_bundle(self, obj_type: str, obj_id: ObjectId, bundle) -> bool: | def put_bundle(self, bundle_type: str, obj_id: ObjectId, bundle) -> bool: | ||||
self._cache.add(obj_type, hash_to_bytes(obj_id), bundle) | self._cache.add(bundle_type, hash_to_bytes(obj_id), bundle) | ||||
return True | return True | ||||
def send_notif(self, obj_type: str, obj_id: ObjectId): | def send_notif(self, bundle_type: str, obj_id: ObjectId): | ||||
pass | pass | ||||
# Batch endpoints | # Batch endpoints | ||||
def batch_cook(self, batch: List[Tuple[str, str]]) -> int: | def batch_cook(self, batch: List[Tuple[str, str]]) -> int: | ||||
raise NotImplementedError("InMemoryVaultBackend.batch_cook()") | raise NotImplementedError("InMemoryVaultBackend.batch_cook()") | ||||
def batch_progress(self, batch_id: int) -> Dict[str, Any]: | def batch_progress(self, batch_id: int) -> Dict[str, Any]: | ||||
pass | pass |