fix(sync): stop retrying a workout Garmin confirms is gone
fillPendingWorkouts previously treated every get_workout_by_id failure identically -- log it, leave workout_raw_json null, retry next sync -- which is correct for a transient failure but means a definitive 404 (the workout deleted on Garmin's side after being linked to an activity) got silently retried forever, with the only symptom being an unexplained, permanent "1 more workout pending" nudge. Now checks errors.Is(err, garmin.ErrNotFound) and, only for that case, calls SetActivityWorkoutNotFound instead of retrying.
This commit is contained in:
@@ -7,6 +7,7 @@ package sync
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
@@ -363,7 +364,18 @@ func (s *Service) fillPendingWorkouts(ctx context.Context, limit int) error {
|
||||
}
|
||||
}
|
||||
if err := s.fillActivityWorkout(ctx, a, profile); err != nil {
|
||||
log.Printf("sync: fill workout for activity %d failed, will retry next sync: %v", a.GarminActivityID, err)
|
||||
if errors.Is(err, garmin.ErrNotFound) {
|
||||
// A definitive 404 (the workout was deleted on Garmin's side
|
||||
// after being linked to this activity) will never succeed on
|
||||
// retry -- mark it so ActivitiesMissingWorkout stops
|
||||
// surfacing it, instead of retrying forever.
|
||||
log.Printf("sync: workout for activity %d not found on Garmin, marking as such (will not retry): %v", a.GarminActivityID, err)
|
||||
if serr := s.db.SetActivityWorkoutNotFound(ctx, s.userID, a.ID); serr != nil {
|
||||
return fmt.Errorf("mark activity %d workout not found: %w", a.GarminActivityID, serr)
|
||||
}
|
||||
} else {
|
||||
log.Printf("sync: fill workout for activity %d failed, will retry next sync: %v", a.GarminActivityID, err)
|
||||
}
|
||||
}
|
||||
s.setProgress(PhaseWorkouts, i+1, len(pending))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user