fishion / StravaImporter

script to import tcx files (as exported by Endomondo) into Strava
24 stars 8 forks source link

Duplicate callbacks and many API calls #5

Closed fighterii closed 3 years ago

fighterii commented 3 years ago

Hey,

first of all - thank you for your work.

I have a question: How many API Calls are necessary for a successful upload?

I got the following output:

processing file 11 of 187 : data/Workouts/2012-08-14 08_23_04.0.tcx
47 of 100 short term API calls made
47 of 1000 long term API calls made
Duplicate callback. Already dealt with 2012-08-01 16_21_02.0.tcx - it was a success

seems like apprx. 4-5 api calls per file are made? And why those duplicate callbacks when its the first time i started the script?

I had several approches to get the process started within Visual Studio Code, but the internal terminal didn't supported the prompts, so the process got stuck and i terminated them. Then i started via cmd one process and it worked - but with the output that seems to have some race conditions/multiple api calls? Is this just something i observe?

processing file 37 of 187 : data/Workouts/2014-02-13 10_16_44.0.tcx
64 of 100 short term API calls made
158 of 1000 long term API calls made
Duplicate callback. Already dealt with 2014-02-11 09_54_26.0.tcx - it was a success
waiting for upload to complete
waiting for upload to complete
waiting for upload to complete
waiting for upload to complete
File 2014-02-13 10_16_44.0.tcx processed OK!
2014-02-13 10_16_44.0.tcx moved to Workouts_Success dir
processing file 38 of 187 : data/Workouts/2014-02-25 09_36_10.0.tcx
69 of 100 short term API calls made
163 of 1000 long term API calls made
Duplicate callback. Already dealt with 2014-02-13 10_16_44.0.tcx - it was a success

=> workout 2014-02-13 10_16_44.0.tcx is file 37; get the processed OK! message and shortly after gets the duplicate callback,

fishion commented 3 years ago

The underlying API client library makes a call every second to check the upload status. For me it was taking 4 or 5 seconds for each upload to complete, so you're right that it does make an unnecessarily large number of API calls per upload really. I thought about trying to monkey patch the library to change that and preserve API calls, but in the end decided it probably wasn't worth the effort, and I could tolerate just waiting a bit longer for the script to complete.

You're right about the race condition/duplicate callback thing too. Couldn't quite work out exactly why it was happening, but I think something to do with the underlying API client library being originally designed to use callbacks but also now supporting Promises, which is the interface I preferred. Again, it didn't seem to affect the correct behaviour of the script so I didn't think it was important enough to spend more time trying to resolve.