Add rate limiting and export progress tracking #75
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is in two parts: the rate limiting itself, and the progress UI.
Rate Limiting
On the rate limiting topic, I reviewed the discussion here and the proposal here. The problem with a throttling approach, as mentioned, is that two users with independently throttled requests can still encounter rate limiting due to the combined throughput. Additionally, it seems to me that we're also required to take a guess as to what level of throttling is acceptable (for example 10 requests per second), but since I can't find it in the documentation there's presumably no guarantee that this won't change either temporarily or permanently on their side.
The approach I've taken here is the one described in their documentation:
This way, it's the server itself that tells each client how long to wait, and so it should work fine across multiple users and is also resistant to any change in logic on Spotify's side. Furthermore, we can run requests as fast as we like until the server tells us otherwise, which should hopefully result in the fastest possible export times.
If we do want to add basic throttling at any point, I've added the bottleneck job scheduler and rate limiter which can be simply and transparently configured to allow this. I've tried to isolate the rate limiting as much as possible from the app logic itself since it's really an implementation detail.
Progress UI
The other part of this feature, which I'd wanted to add sooner, is a clearer indication of how long the export will take.
Here's how it looks:
I did think about adding some indication to the UI that the export was paused due to a rate limiting delay, but decided not to because I want to keep the interface as simple as possible, and: