Spaces:
Running
Running
Use typed Settings for canonical asset retention
Browse files- app/security/assets.py +6 -2
app/security/assets.py
CHANGED
|
@@ -11,6 +11,7 @@ from typing import Any
|
|
| 11 |
from sqlalchemy import select
|
| 12 |
from sqlalchemy.exc import IntegrityError
|
| 13 |
|
|
|
|
| 14 |
from app.security.database import SecurityDatabase
|
| 15 |
from app.security.models import CanonicalMediaAsset
|
| 16 |
|
|
@@ -27,8 +28,9 @@ class CanonicalAssetService:
|
|
| 27 |
``CleanupService`` so every consumer receives the same traversal checks.
|
| 28 |
"""
|
| 29 |
|
| 30 |
-
def __init__(self, database: SecurityDatabase) -> None:
|
| 31 |
self.database = database
|
|
|
|
| 32 |
|
| 33 |
async def register_output(
|
| 34 |
self,
|
|
@@ -167,7 +169,9 @@ class CanonicalAssetService:
|
|
| 167 |
Project-attached assets are retained. Missing files are reconciled from
|
| 168 |
the database so stale asset IDs cannot accumulate indefinitely.
|
| 169 |
"""
|
| 170 |
-
hours =
|
|
|
|
|
|
|
| 171 |
cutoff = datetime.now(timezone.utc) - timedelta(hours=hours)
|
| 172 |
removed = 0
|
| 173 |
async with self.database.session() as session:
|
|
|
|
| 11 |
from sqlalchemy import select
|
| 12 |
from sqlalchemy.exc import IntegrityError
|
| 13 |
|
| 14 |
+
from app.core.config import Settings
|
| 15 |
from app.security.database import SecurityDatabase
|
| 16 |
from app.security.models import CanonicalMediaAsset
|
| 17 |
|
|
|
|
| 28 |
``CleanupService`` so every consumer receives the same traversal checks.
|
| 29 |
"""
|
| 30 |
|
| 31 |
+
def __init__(self, database: SecurityDatabase, settings: Settings | None = None) -> None:
|
| 32 |
self.database = database
|
| 33 |
+
self.settings = settings
|
| 34 |
|
| 35 |
async def register_output(
|
| 36 |
self,
|
|
|
|
| 169 |
Project-attached assets are retained. Missing files are reconciled from
|
| 170 |
the database so stale asset IDs cannot accumulate indefinitely.
|
| 171 |
"""
|
| 172 |
+
hours = self.settings.asset_retention_hours if self.settings is not None else max(
|
| 173 |
+
1, int(os.getenv("MEDIA_ASSET_RETENTION_HOURS", "24"))
|
| 174 |
+
)
|
| 175 |
cutoff = datetime.now(timezone.utc) - timedelta(hours=hours)
|
| 176 |
removed = 0
|
| 177 |
async with self.database.session() as session:
|