This commit is contained in:
2025-11-17 06:26:36 -08:00
parent 7d4ffcd902
commit 06419077b4
6 changed files with 485 additions and 353 deletions

View File

@@ -35,7 +35,8 @@ class WorkoutSyncService:
start_date = datetime.now() - timedelta(days=days_back)
logger.debug(f"Fetching activities from Garmin starting from: {start_date}")
# Fetch activities from Garmin
# Authenticate and fetch activities from Garmin
await self.garmin_service.authenticate()
activities = await self.garmin_service.get_activities(
limit=50, start_date=start_date, end_date=datetime.now()
)
@@ -109,7 +110,8 @@ class WorkoutSyncService:
sync_log.status = GarminSyncStatus.FAILED
sync_log.error_message = str(e)
await self.db.commit()
raise
# Wrap unexpected errors in GarminAPIError for consistent error handling
raise GarminAPIError(f"An unexpected error occurred: {e}") from e
async def get_latest_sync_status(self):
"""Get the most recent sync log entry."""
@@ -119,7 +121,7 @@ class WorkoutSyncService:
.order_by(desc(GarminSyncLog.created_at))
.limit(1)
)
status = result.scalar_one_or_none()
status = await result.scalar_one_or_none()
logger.debug(f"Latest sync status: {status.status if status else 'None'}")
return status
@@ -129,7 +131,7 @@ class WorkoutSyncService:
result = await self.db.execute(
select(Workout).where(Workout.garmin_activity_id == garmin_activity_id)
)
exists = result.scalar_one_or_none() is not None
exists = await result.scalar_one_or_none() is not None
logger.debug(f"Activity {garmin_activity_id} exists: {exists}")
return exists