diff --git a/antarest/study/storage/auto_archive_service.py b/antarest/study/storage/auto_archive_service.py index dc2795bfa4..23e5914d8c 100644 --- a/antarest/study/storage/auto_archive_service.py +++ b/antarest/study/storage/auto_archive_service.py @@ -48,9 +48,8 @@ def _try_archive_studies(self) -> None: study_ids_to_archive = [ (study.id, isinstance(study, RawStudy)) for study in studies - if ((study.last_access or study.updated_at) < old_date) - and isinstance(study, VariantStudy) - or not study.archived + if (study.last_access or study.updated_at) < old_date + and (isinstance(study, VariantStudy) or not study.archived) ] for study_id, is_raw_study in study_ids_to_archive[0 : self.max_parallel]: try: @@ -87,10 +86,10 @@ def _try_archive_studies(self) -> None: def _try_clear_snapshot(self) -> None: # convert days in hours - hours_of_lifespan = hours=self.config.storage.variant_snapshot_lifespan_days * 24 + hours_of_lifespan = self.config.storage.variant_snapshot_lifespan_days * 24 self.study_service.storage_service.variant_study_service.clear_all_snapshots( - hours_of_lifespan + datetime.timedelta(hours=hours_of_lifespan) ) def _loop(self) -> None: diff --git a/tests/storage/business/test_autoarchive_service.py b/tests/storage/business/test_autoarchive_service.py index 52fb4d436d..7d1b0c94a7 100644 --- a/tests/storage/business/test_autoarchive_service.py +++ b/tests/storage/business/test_autoarchive_service.py @@ -69,18 +69,6 @@ def test_auto_archival(tmp_path: Path): id="e", updated_at=now - datetime.timedelta(days=61), ), - VariantStudy( - id="f", - updated_at=now - datetime.timedelta(days=0), - ), - VariantStudy( - id="g", - updated_at=now - datetime.timedelta(days=1), - ), - VariantStudy( - id="h", - last_access=now - datetime.timedelta(days=2) - ) ] ) db_session.commit() @@ -109,7 +97,8 @@ def test_auto_archival(tmp_path: Path): # Check that the variant outputs are deleted for the variant study "e" study_service.archive_outputs.assert_called_once_with("e", params=RequestParameters(DEFAULT_ADMIN_USER)) - # Test auto snapshot clearing + # Check if the `clear_all_snapshots` method was called with default values auto_archive_service._try_clear_snapshot() - - # Check if variant snapshots with date older than variant_snapshot_lifespan_days argument are cleared + study_service.storage_service.variant_study_service.clear_all_snapshots.assert_called_once_with( + datetime.timedelta(hours=24), + )