feat: Implement Garmin sync, login improvements, and utility scripts

This commit is contained in:
2025-10-11 11:56:25 -07:00
parent 56a93cd8df
commit 3819e4f5e2
921 changed files with 2058 additions and 371 deletions

View File

@@ -1,12 +1,11 @@
import logging
import uuid
from datetime import datetime
from typing import Optional, List, Dict, Any
from typing import Any, Dict, Optional
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential
from ..services.garmin_client_service import GarminClientService
from ..jobs import job_store
from ..services.garmin_client_service import GarminClientService
logger = logging.getLogger(__name__)
@@ -26,8 +25,8 @@ class GarminWorkoutService:
async def upload_workout(self, workout_id: uuid.UUID) -> Optional[Dict[str, Any]]:
try:
# Get workout from CentralDB
from .central_db_service import CentralDBService
from ..config import settings
from .central_db_service import CentralDBService
central_db = CentralDBService(base_url=settings.CENTRAL_DB_URL)
workout = await central_db.get_workout_by_id(workout_id) # Assuming this method exists
@@ -39,18 +38,26 @@ class GarminWorkoutService:
if not garmin_client:
raise Exception("Garmin client not authenticated.")
logger.info(f"Simulating upload of workout {workout.name} (ID: {workout_id}) to Garmin Connect.")
logger.info(
f"Simulating upload of workout {workout.name} (ID: {workout_id}) "
"to Garmin Connect."
)
garmin_workout_id = f"GARMIN_WORKOUT_{workout_id}" # Mock ID
# Here we would update the workout in CentralDB with the garmin_workout_id
# await central_db.update_workout(workout_id, {"garmin_workout_id": garmin_workout_id, "upload_status": "completed"})
# await central_db.update_workout(
# workout_id, {"garmin_workout_id": garmin_workout_id, "upload_status": "completed"}
# )
logger.info(
f"Successfully uploaded workout {workout.name} to Garmin Connect "
f"with ID {garmin_workout_id}."
)
logger.info(f"Successfully uploaded workout {workout.name} to Garmin Connect with ID {garmin_workout_id}.")
# We need to add garmin_workout_id to the workout dictionary before returning
workout_dict = workout.dict()
workout_dict["garmin_workout_id"] = garmin_workout_id
return workout_dict
except Exception as e:
@@ -70,10 +77,25 @@ class GarminWorkoutService:
uploaded_workout = await self.upload_workout(workout_id)
if uploaded_workout:
job_store.update_job(job_id, status="completed", progress=1.0, details={"uploaded_workout_id": str(uploaded_workout.id), "garmin_workout_id": uploaded_workout.garmin_workout_id})
job_store.update_job(
job_id,
status="completed",
progress=1.0,
details={
"uploaded_workout_id": str(uploaded_workout.id),
"garmin_workout_id": uploaded_workout.garmin_workout_id
}
)
else:
job_store.update_job(job_id, status="failed", progress=1.0, error_message=f"Failed to upload workout {workout_id}")
job_store.update_job(
job_id,
status="failed",
progress=1.0,
error_message=f"Failed to upload workout {workout_id}"
)
except Exception as e:
logger.error(f"Error during workout upload for job {job_id}: {e}", exc_info=True)
job_store.update_job(job_id, status="failed", progress=1.0, error_message=str(e))
logger.error(
f"Error during workout upload for job {job_id}: {e}", exc_info=True
)
job_store.update_job(job_id, status="failed", progress=1.0, error_message=str(e))