Skip to content

Commit

Permalink
Store files a hour longer then they are displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Jul 28, 2024
1 parent 7b7234d commit 040d5a9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package_build/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_file_modification_datetime(path: Path) -> datetime:
return datetime.fromtimestamp(path.stat().st_mtime, tz=timezone.utc)


def package_up_to_date(package_path: Path) -> bool:
def package_up_to_date(package_path: Path, lifetime: timedelta = timedelta(hours=12)) -> bool:
"""
Check if the package is up to date: it exists and it was created not earlier then 12 hours ago.
"""
Expand All @@ -63,10 +63,10 @@ def package_up_to_date(package_path: Path) -> bool:
return False

modification_datetime = get_file_modification_datetime(package_path)
return (modification_datetime + timedelta(hours=12)) > datetime.now(tz=timezone.utc)
return (modification_datetime + lifetime) > datetime.now(tz=timezone.utc)


def remove_stale_packages(root_dir: Path) -> None:
for package_path in root_dir.glob("*.zip"):
if not package_up_to_date(package_path):
if not package_up_to_date(package_path, lifetime=timedelta(hours=13)):
package_path.unlink(missing_ok=True)

0 comments on commit 040d5a9

Please sign in to comment.