intervall
This commit is contained in:
@@ -89,6 +89,20 @@ class SystemLogEntry(Base):
|
||||
user_id: Mapped[int | None] = mapped_column(ForeignKey("sync_users.id", ondelete="SET NULL"))
|
||||
|
||||
|
||||
class SchedulerSettings(Base):
|
||||
"""Singleton row (id is always 1) holding the admin-configurable day/night
|
||||
sync interval -- editable at runtime via the UI, unlike SYNC_INTERVAL_MINUTES
|
||||
which only seeds this row's initial values on first startup."""
|
||||
|
||||
__tablename__ = "scheduler_settings"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
day_start_hour: Mapped[int] = mapped_column(Integer, nullable=False, default=6)
|
||||
night_start_hour: Mapped[int] = mapped_column(Integer, nullable=False, default=22)
|
||||
day_interval_minutes: Mapped[int] = mapped_column(Integer, nullable=False, default=5)
|
||||
night_interval_minutes: Mapped[int] = mapped_column(Integer, nullable=False, default=5)
|
||||
|
||||
|
||||
class SyncRun(Base):
|
||||
__tablename__ = "sync_runs"
|
||||
|
||||
|
||||
@@ -5,7 +5,18 @@ 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, SystemLogEntry, SyncUser, utcnow
|
||||
from app.db.models import (
|
||||
Activity,
|
||||
ActivityStatus,
|
||||
SchedulerSettings,
|
||||
SyncRun,
|
||||
SyncRunStatus,
|
||||
SystemLogEntry,
|
||||
SyncUser,
|
||||
utcnow,
|
||||
)
|
||||
|
||||
_SCHEDULER_SETTINGS_ID = 1
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -211,6 +222,29 @@ class SystemLogRepository:
|
||||
)
|
||||
|
||||
|
||||
class SchedulerSettingsRepository:
|
||||
def __init__(self, session: Session) -> None:
|
||||
self.session = session
|
||||
|
||||
def get_or_create(self, *, default_minutes: int = 5) -> SchedulerSettings:
|
||||
row = self.session.get(SchedulerSettings, _SCHEDULER_SETTINGS_ID)
|
||||
if row is None:
|
||||
row = SchedulerSettings(
|
||||
id=_SCHEDULER_SETTINGS_ID,
|
||||
day_interval_minutes=default_minutes,
|
||||
night_interval_minutes=default_minutes,
|
||||
)
|
||||
self.session.add(row)
|
||||
self.session.commit()
|
||||
return row
|
||||
|
||||
def update(self, row: SchedulerSettings, **values) -> SchedulerSettings:
|
||||
for key, value in values.items():
|
||||
setattr(row, key, value)
|
||||
self.session.commit()
|
||||
return row
|
||||
|
||||
|
||||
class SyncRunRepository:
|
||||
def __init__(self, session: Session) -> None:
|
||||
self.session = session
|
||||
|
||||
Reference in New Issue
Block a user