jovandeginste / workout-tracker

A workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities
Other
945 stars 31 forks source link

Wishlist: Automatic gpx import #40

Closed tjhowse closed 6 months ago

tjhowse commented 6 months ago

I sync GPX files from fitotrack to my server. I would love to drop them into a directory and have them automatically import into workout-tracker.

It might be less work overall to write a crontask to curl the GPX files to the workouts endpoint, provided I can get the auth sorted out.

In any case: Love this project! I just imported 401 workouts into my instance in one go. It took a few minutes but worked perfectly. Thanks hugely!

jovandeginste commented 6 months ago

I wanted to either add an API endpoint, or a directory per user to auto-import from.

What are the thoughts? Should the files be deleted on successful import in case of the directory?

tjhowse commented 6 months ago

Here's how I'd do it:

  1. Poll directory contents every x seconds for files.
  2. If a new file appears: store its file size and schedule another poll in 5 seconds,
  3. If a file's size hasn't changed on the second poll: Queue it for import.
  4. Once an import has finished, create an "archive" subdirectory if it doesn't already exist and move the imported file into it.

This system gives us reasonable confidence we're not going to start importing a file while it's still being written to disk, and avoids deleting anything. Does that sound reasonable?

jovandeginste commented 6 months ago

I'll make a PoC with this flow: