Skip to content

Conversation

@chrisandreae
Copy link
Member

If Phraseapp is slow to process uploads, we can hit the rate limit while waiting to verify them.

@chrisandreae chrisandreae force-pushed the backoff-verify-upload branch from 0ef7771 to cf42ab5 Compare April 21, 2025 07:59
end
end

sleep(2) unless uploads.empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developers.phrase.com/api/#overview--rate-limiting

In theory you can make 1 request every 3.333 seconds and not hit the rate limit. So I think if you actually just bumped this line to 4 it would maintain okay.

This says "per user" so I'm not sure if they really mean per client.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you actually just bumped this line to 4 it would maintain okay

This is doing up to a request per language each time around the loop, so it's a bit multiplied out.

This says "per user" so I'm not sure if they really mean per client.

It's a complete assumption, but I was assuming they meant "per API key".

Comment on lines +248 to +255
# If we bail mid-sync, it can be expensive to recover from a partial
# merge. Instead, aggressively try to retry.
if retries >= 0
retries -= 1
STDERR.puts('Rate limited, retrying in 5...')
sleep(5)
retry
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically they return a X-Rate-Limit-Reset which tells you when the rate limit should be okay again 🤷 It's not clear to me if 5 seconds is sufficient or not. If the reset goes back to 100% after 5 minutes though I wouldn't see much harm in just sleeping for 5 minutes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 seconds may well be insufficient, but even if each failed request is itself counted towards the rate-limit, it's still slow enough that the pool will eventually drain and we'll be able to make the request. So it might be somewhat lazy behaviour, but I think it's safe.

@chrisandreae chrisandreae force-pushed the backoff-verify-upload branch from c68b30e to 00e76fa Compare April 21, 2025 09:24
If Phraseapp is slow to process uploads, we can hit the rate limit while waiting to verify them.
@chrisandreae chrisandreae force-pushed the backoff-verify-upload branch from 352170c to 25bf28a Compare April 21, 2025 09:29
@chrisandreae chrisandreae merged commit 0a4c0c1 into master Apr 21, 2025
4 checks passed
@chrisandreae chrisandreae deleted the backoff-verify-upload branch April 21, 2025 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants