update retention policy to a maximum of 2 days for completed archives and adjust related configurations
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user