Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/vault/api/cooking_tasks.py
# Copyright (C) 2016 The Software Heritage developers | # Copyright (C) 2016 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 | ||||
from swh.scheduler.task import Task | from swh.scheduler.task import Task | ||||
from swh.core import hashutil | from swh.core import hashutil | ||||
from ..cache import VaultCache | from ..cache import VaultCache | ||||
from ..cooker import DirectoryVaultCooker | from ..cooker import DirectoryVaultCooker | ||||
from ... import get_storage | from ... import get_storage | ||||
COOKER_TYPES = { | |||||
'directory': DirectoryVaultCooker | |||||
} | |||||
class SWHCookingTask(Task): | class SWHCookingTask(Task): | ||||
""" Main task that archive a batch of content. | """ Main task that archive a batch of content. | ||||
""" | """ | ||||
task_queue = 'swh_storage_vault_cooking' | task_queue = 'swh_storage_vault_cooking' | ||||
def run(self, hex_dir_id, storage_args, cache_args): | def run(self, type, hex_dir_id, storage_args, cache_args): | ||||
# Initialize elements | |||||
storage = get_storage(**storage_args) | storage = get_storage(**storage_args) | ||||
cache = VaultCache(**cache_args) | cache = VaultCache(**cache_args) | ||||
directory_cooker = DirectoryVaultCooker(storage, cache) | # Initialize cooker | ||||
vault_cooker_class = COOKER_TYPES[type] | |||||
cooker = vault_cooker_class(storage, cache) | |||||
# Perform the cooking | |||||
dir_id = hashutil.hex_to_hash(hex_dir_id) | dir_id = hashutil.hex_to_hash(hex_dir_id) | ||||
directory_cooker.cook(dir_id) | cooker.cook(dir_id) |