update retention policy to a maximum of 2 days for completed archives and adjust related configurations

This commit is contained in:
kstyagi23
2026-09-05 06:37:35 +05:30
parent 48402f7d61
commit 9c1a301c1a
10 changed files with 477 additions and 92 deletions
+17 -2
View File
@@ -9,6 +9,8 @@ from datetime import UTC, datetime, timedelta
from pathlib import Path
from typing import Any
from app.config import MAX_ARCHIVE_RETENTION_DAYS
def utcnow() -> datetime:
return datetime.now(UTC)
@@ -494,6 +496,7 @@ class Database:
) -> bool:
now_datetime = utcnow()
now = timestamp(now_datetime)
retention_days = min(retention_days, MAX_ARCHIVE_RETENTION_DAYS)
with self.connection() as connection:
cursor = connection.execute(
"""
@@ -644,10 +647,22 @@ class Database:
)
def expired_ready_jobs(self) -> list[dict[str, Any]]:
now = timestamp()
now_datetime = utcnow()
now = timestamp(now_datetime)
maximum_completion_age = timestamp(
now_datetime - timedelta(days=MAX_ARCHIVE_RETENTION_DAYS)
)
with self.connection() as connection:
rows = connection.execute(
"SELECT * FROM jobs WHERE state = 'ready' AND expires_at <= ?", (now,)
"""
SELECT * FROM jobs
WHERE state = 'ready'
AND (
expires_at <= ?
OR COALESCE(completed_at, created_at) <= ?
)
""",
(now, maximum_completion_age),
).fetchall()
return [self._row_to_job(row) for row in rows]