log
This commit is contained in:
@@ -5,7 +5,7 @@ from sqlalchemy import and_, or_, select
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.models import Activity, ActivityStatus, SyncRun, SyncRunStatus, SyncUser, utcnow
|
||||
from app.db.models import Activity, ActivityStatus, SyncRun, SyncRunStatus, SystemLogEntry, SyncUser, utcnow
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -191,6 +191,26 @@ class ActivityRepository:
|
||||
)
|
||||
|
||||
|
||||
class SystemLogRepository:
|
||||
def __init__(self, session: Session) -> None:
|
||||
self.session = session
|
||||
|
||||
def add(self, *, source: str, message: str, user_id: int | None = None) -> SystemLogEntry:
|
||||
entry = SystemLogEntry(source=source, message=message[:2000], user_id=user_id)
|
||||
self.session.add(entry)
|
||||
self.session.commit()
|
||||
return entry
|
||||
|
||||
def list_recent(self, limit: int = 50) -> list[SystemLogEntry]:
|
||||
return list(
|
||||
self.session.scalars(
|
||||
select(SystemLogEntry)
|
||||
.order_by(SystemLogEntry.created_at.desc(), SystemLogEntry.id.desc())
|
||||
.limit(limit)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class SyncRunRepository:
|
||||
def __init__(self, session: Session) -> None:
|
||||
self.session = session
|
||||
|
||||
Reference in New Issue
Block a user