Skip to content

Commit

Permalink
Reset retrieval data
Browse files Browse the repository at this point in the history
  • Loading branch information
islean committed Jan 9, 2024
1 parent ec46cd1 commit 79b867d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions cg/meta/clean/clean_retrieved_spring_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@ def _get_files_to_remove(self) -> list[File]:
date=datetime.datetime.now() - datetime.timedelta(days=7)
)

def clean_retrieved_spring_files(self, dry_run: bool):
"""Removes Spring files which were retrieved more than 7 days ago."""
files_to_remove: list[File] = self._get_files_to_remove()
def _unlink_files(self, files_to_remove: list[File], dry_run: bool) -> None:
for file in files_to_remove:
file_path: str = file.full_path
if dry_run:
LOG.info("Dry run - would have unlinked file_path")
LOG.info(f"Dry run - would have unlinked {file_path}")
LOG.info(f"Unlinking {file_path}")
Path(file_path).unlink(missing_ok=True)

def _reset_retrieved_archive_data(self, files_to_remove: list[File]):
"""Resets 'retrieval task id' and 'retrieved at' for all files' corresponding archive entries"""
for file in files_to_remove:
file.archive.retrieval_task_id = None
file.archive.retrieved_at = None
self.housekeeper_api.commit()

def clean_retrieved_spring_files(self, dry_run: bool):
"""Removes Spring files which were retrieved more than 7 days ago."""
files_to_remove: list[File] = self._get_files_to_remove()
self._unlink_files(files_to_remove=files_to_remove, dry_run=dry_run)
if not dry_run:
self._reset_retrieved_archive_data(files_to_remove)
else:
LOG.info("Would have resetted the files' retrieval data")

0 comments on commit 79b867d

Please sign in to comment.