Skip to content

Commit

Permalink
Merge pull request #203 from jovandeginste/fix-update-non-gpx
Browse files Browse the repository at this point in the history
Skip updates for non-GPX based workouts
  • Loading branch information
jovandeginste authored Jul 31, 2024
2 parents 59f066b + 9fd9480 commit 3d1ccfd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/app/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,27 @@ const (
)

func (a *App) BackgroundWorker() {
for {
a.bgLoop()
time.Sleep(WorkerDelay)
}
}

func (a *App) bgLoop() {
l := a.logger.With("module", "worker")

for {
l.Info("Worker started...")
defer func() {
if r := recover(); r != nil {
l.Error(fmt.Sprintf("Panic in bgLoop: %#v", r))
}
}()

a.updateWorkout(l)
a.autoImports(l)
l.Info("Worker started...")

l.Info("Worker finished...")
time.Sleep(WorkerDelay)
}
a.updateWorkout(l)
a.autoImports(l)

l.Info("Worker finished...")
}

func (a *App) autoImports(l *slog.Logger) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/database/workouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ func (w *Workout) Save(db *gorm.DB) error {
}

func (w *Workout) AsGPX() (*gpx.GPX, error) {
if w.GPX == nil {
return nil, errors.New("workout has no GPX")
}

return converters.Parse(w.GPX.Filename, w.GPX.Content)
}

Expand All @@ -250,6 +254,11 @@ func (w *Workout) setData(data *MapData) {
}

func (w *Workout) UpdateData(db *gorm.DB) error {
if w.GPX == nil {
// We only update data from (stored) GPX data
return nil
}

gpxContent, err := w.AsGPX()
if err != nil {
return err
Expand Down

0 comments on commit 3d1ccfd

Please sign in to comment.