diff --git a/swh/deposit/api/common.py b/swh/deposit/api/common.py --- a/swh/deposit/api/common.py +++ b/swh/deposit/api/common.py @@ -31,7 +31,6 @@ STATE_IRI, DEPOSIT_STATUS_DEPOSITED, DEPOSIT_STATUS_PARTIAL, - PRIVATE_CHECK_DEPOSIT, DEPOSIT_STATUS_LOAD_SUCCESS, ARCHIVE_TYPE, METADATA_TYPE, @@ -195,14 +194,12 @@ if self.config["checks"]: deposit.save() # needed to have a deposit id - args = [deposit.collection.name, deposit.id] scheduler = self.scheduler if deposit.status == DEPOSIT_STATUS_DEPOSITED and not deposit.check_task_id: - check_url = request.build_absolute_uri( - reverse(PRIVATE_CHECK_DEPOSIT, args=args) - ) task = create_oneshot_task_dict( - "check-deposit", deposit_check_url=check_url + "check-deposit", + collection=deposit.collection.name, + deposit_id=deposit.id, ) check_task_id = scheduler.create_tasks([task])[0]["id"] deposit.check_task_id = check_task_id diff --git a/swh/deposit/loader/checker.py b/swh/deposit/loader/checker.py --- a/swh/deposit/loader/checker.py +++ b/swh/deposit/loader/checker.py @@ -7,25 +7,34 @@ from typing import Mapping +from swh.core.config import SWHConfig + from swh.deposit.client import PrivateApiDepositClient logger = logging.getLogger(__name__) -class DepositChecker: +class DepositChecker(SWHConfig): """Deposit checker implementation. Trigger deposit's checks through the private api. """ - def __init__(self, client=None): + CONFIG_BASE_FILENAME = "deposit/checker" + + DEFAULT_CONFIG = { + "deposit": ("dict", {"url": "http://localhost:5006", "auth": {},}) + } + + def __init__(self): super().__init__() - self.client = client if client else PrivateApiDepositClient() + self.client = PrivateApiDepositClient(**self.config["deposit"]) - def check(self, deposit_check_url: str) -> Mapping[str, str]: + def check(self, collection: str, deposit_id: str) -> Mapping[str, str]: status = None + deposit_check_url = f"{collection}/{deposit_id}/check" try: r = self.client.check(deposit_check_url) status = "eventful" if r == "verified" else "failed" diff --git a/swh/deposit/tests/api/test_deposit_schedule.py b/swh/deposit/tests/api/test_deposit_schedule.py --- a/swh/deposit/tests/api/test_deposit_schedule.py +++ b/swh/deposit/tests/api/test_deposit_schedule.py @@ -76,9 +76,11 @@ task = tasks[0] assert timestamp_before_call <= task.pop("next_run") <= timestamp_after_call - check_url = f"http://testserver/1/private/test/{deposit_id}/check/" assert task == { - "arguments": {"args": [], "kwargs": {"deposit_check_url": check_url,},}, + "arguments": { + "args": [], + "kwargs": {"collection": "test", "deposit_id": int(deposit_id),}, + }, "current_interval": datetime.timedelta(days=1), "id": 1, "policy": "oneshot",