This commit is contained in:
Bastian Wagner
2026-08-15 20:54:35 +02:00
parent 2aba1265af
commit 420d089760
9 changed files with 178 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ from pathlib import Path
from typing import Any, Callable
from app.db.models import ActivityStatus, HealthState, SyncRunStatus
from app.db.repositories import ActivityRepository, SyncRunRepository, UserRepository
from app.db.repositories import ActivityRepository, SyncRunRepository, SystemLogRepository, UserRepository
from app.fit.rewriter import FitFormatError
from app.garmin.uploader import (
GarminAuthError,
@@ -76,7 +76,7 @@ class SyncManager:
self._locks: dict[int, asyncio.Lock] = {}
self._locks_guard = asyncio.Lock()
def _notify_action_required(self, user: Any, message: str | None) -> None:
def _notify_action_required(self, session: Any, user: Any, message: str | None) -> None:
if self.notifier is None or not user.notify_email_enabled or not user.notification_email:
return
try:
@@ -85,10 +85,21 @@ class SyncManager:
subject=f"MyWhoosh-Garmin Sync: action required for {user.name}",
body=message or "Your sync requires attention. Check the dashboard for details.",
)
except Exception:
except Exception as exc:
logger.warning(
"sync_user: failed to send action-required notification for user %s", user.id, exc_info=True
)
try:
SystemLogRepository(session).add(
source="email_notification",
message=(
f"Failed to email {user.notification_email} for user {user.id} ({user.name}): "
f"{type(exc).__name__}: {exc}"
),
user_id=user.id,
)
except Exception:
logger.warning("sync_user: failed to record email-notification failure in system log", exc_info=True)
async def _lock_for(self, user_id: int) -> asyncio.Lock:
async with self._locks_guard:
@@ -389,7 +400,7 @@ class SyncManager:
)
session.commit()
if user.action_reason is not None and user.action_reason != previous_action_reason:
self._notify_action_required(user, summary_error)
self._notify_action_required(session, user, summary_error)
return SyncOutcome(
user_id=user.id,
status=status.value,