diff --git a/swh/loader/core/loader.py b/swh/loader/core/loader.py --- a/swh/loader/core/loader.py +++ b/swh/loader/core/loader.py @@ -14,7 +14,8 @@ from swh.core import config from swh.model.model import ( BaseContent, Content, SkippedContent, Directory, Origin, Revision, - Release, Snapshot) + Release, Sha1Git, Snapshot +) from swh.storage import get_storage @@ -254,6 +255,10 @@ """ return 'full' + def get_snapshot_id(self) -> Optional[Sha1Git]: + """Get the snapshot id that needs to be loaded""" + raise NotImplementedError + def pre_cleanup(self) -> None: """As a first step, will try and check for dangling data to cleanup. This should do its best to avoid raising issues. @@ -301,7 +306,8 @@ self.store_metadata() self.storage.origin_visit_update( - self.origin.url, self.visit.visit, self.visit_status() + self.origin.url, self.visit.visit, self.visit_status(), + snapshot=self.get_snapshot_id() ) self.post_load() except Exception: @@ -311,7 +317,8 @@ 'swh_task_kwargs': kwargs, }) self.storage.origin_visit_update( - self.origin.url, self.visit.visit, 'partial' + self.origin.url, self.visit.visit, 'partial', + snapshot=self.get_snapshot_id() ) self.post_load(success=False) return {'status': 'failed'} @@ -374,6 +381,10 @@ """Get the snapshot that needs to be loaded""" raise NotImplementedError + def get_snapshot_id(self) -> Optional[Sha1Git]: + snapshot = self.get_snapshot() + return snapshot.id if snapshot else None + def eventful(self) -> bool: """Whether the load was eventful""" raise NotImplementedError diff --git a/swh/loader/core/tests/test_loader.py b/swh/loader/core/tests/test_loader.py --- a/swh/loader/core/tests/test_loader.py +++ b/swh/loader/core/tests/test_loader.py @@ -26,6 +26,9 @@ def store_data(self): pass + def get_snapshot_id(self): + return None + def prepare_origin_visit(self, *args, **kwargs): origin = Origin(url='some-url') self.origin = origin